Httparty returns 502 but Postman execution works

Asked

Viewed 27 times

1

I do some APIS testing with httparty and use Postman for smoke testing.

When I call the same process in my ruby class, using httparty, it gives me 502, if in seconds I run on Postman, it gives me 200 and returns the answer I need.

Postman:inserir a descrição da imagem aqui

Httparty:

Traceback (most recent call last):
        1: from features/api/GetCosmic.rb:33:in `<main>'
features/api/GetCosmic.rb:16:in `cosmic': API não funcionou. Código: 502 (RuntimeError)
def cosmic(read_key,marca,opcao) 
        inicio = 0
        fim = 100
        array = []
        while(inicio <= fim)
            response = HTTParty.get("https://api.cosmicjs.com/v1/#{marca}/objects?type=#{opcao}&hide_metafields=true&pretty=true&skip=#{inicio}&limit=#{fim}&read_key=#{read_key}",
                :headers => {'Content-Type' => 'application/json'})
            if response.code != 200
               raise "API não funcionou. Código: #{response.code.to_s}"
               break
            else
                break if response['objects'].nil?
                response['objects'].each do |obj|
                    array.push(obj)
                end
               inicio = fim+1
               fim = fim+100  
            end
        end
        array
    end
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.