【发布时间】:2019-12-06 20:51:39
【问题描述】:
我需要使用 Post 生成一个值并在查询中传递这个值并删除。这该怎么做?
是否可以在请求get或delete的def retrieve方法中直接传递变量的值?
I want to use the same value generated in the var that stores the faker gem and pass both get and delete.
require 'HTTParty'
require 'httparty/request'
require 'httparty/response/headers'
class Crud
include HTTParty
def create
@@codigo = Faker::Number.number(digits: 5)
@nome = Faker::Name.first_name
@salario = Faker::Number.decimal(l_digits: 4, r_digits: 2)
@idade = Faker::Number.number(digits: 2)
@base_url = 'http://dummy.restapiexample.com/api/v1/create'
@body = {
"id":@@codigo,
"name":@nome,
"salary":@salario,
"age":@idade
}.to_json
@headers = {
"Accept": 'application/vnd.tasksmanager.v2',
'Content-Type': 'application/json'
}
@@request = Crud.post(@base_url, body: @body, headers: @headers)
end
def retrieve
self.class.get('http://dummy.restapiexample.com/api/v1/employee/1')
end
end
【问题讨论】: