How can I finish CRUD from API? I have questions on PUT [closed]

最后都变了- 提交于 2019-12-20 07:47:31

问题


I need to generate a put but I don't know how to pass the parameters to update the name, salary or age from Gem Faker. How to upgrade from GEM faker or any even fixed value? I tried but could not.

require 'HTTParty'
require 'httparty/request'
require 'httparty/response/headers'
#require_relative '../hooks/hook'

class Crud

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

def create 
  nome = Faker::Name.unique.first_name
  salario = Faker::Number.decimal(l_digits: 4, r_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

def update(id)
  self.class.put("/update/#{ id }")
end

  ex.: def retrieve
  @response = $manter_user.create
  expect($manter_user.create.code).to eq (200)
  puts @response.body
  @id = JSON.parse(@response)['id']
  puts $manter_user.retrieve(@id) 

But in def update, I don't know how to pass the value to change.

  response = $manter_user.create
  expect(@response.code).to eq (200)
  puts @response.body
  @id = JSON.parse(@response.body)[name][salary][age] --- I don't know what to inform here. 

来源:https://stackoverflow.com/questions/59337200/how-can-i-finish-crud-from-api-i-have-questions-on-put

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!