Cassia Klaison
Cassia Klaison

Reputation: 3

no implicit conversion of HTTParty::Response into String (TypeError) ruby with httparty

This was running without problems, now I'm getting the following error when I use the same ID that I registered in the query: no implicit conversion of HTTParty::Response into String (TypeError)

class Crud
  include HTTParty
  base_uri 'http://dummy.restapiexample.com/api/v1'

  def create 
    nome = Faker::UniqueGenerator.clear
    nome = Faker::Name.unique.first_name
    salario = Faker::Number.number(digits: 2)
    idade   = Faker::Number.number(digits: 2)
    $body = {name: nome, salary: salario, age: idade }.to_json

    $headers = {
      'Accept' => 'application/vnd.tasksmanager.v2',
      'Content-Type' => 'application/json'
    }

    self.class.post('/create', body: $body, headers: $headers) 
  end

  def retrieve(id)
    self.class.get("/employee/#{ id }")
  end 
  
def delete(id)
self.class.delete("/delete/#{ id }")
end


  $response = @manter_user.create
  expect(@manter_user.create.code).to eq (200)
  puts $response.body
  pp @id = JSON.parse($response)["id"]
  *no implicit conversion of HTTParty::Response into String (TypeError)*
  puts @manter_user.retrieve(@id)
  expect(@manter_user.retrieve(@id).code).to eq (200) 

Upvotes: 0

Views: 52

Answers (0)

Related Questions