Examples:
class MyClient < Evil::Client
settings do
option :version, type: Dry::Types["strict.int"].default(1)
option :user, type: Dry::Types["strict.string"]
option :token, type: Dry::Types["strict.string"]
end
base_url do |settings|
"https://my_api.com/v#{settings.version}"
end
connection :net_http do |settings|
run AddCustomRequestId
run EncryptToken if settings.token
end
operation do |settings|
type { :json }
security { basic_auth "foo", "bar" }
end
operation :find_cat do |settings|
http_method :get
path { "#{settings.url}/cats/find/#{id}" }
query do
option :id, type: Dry::Types["coercible.int"].constrained(gt: 0)
end
response 200, type: Cat
response 400, raise: true
response 422, raise: true do |body:|
JSON.parse(body.first)
end
end
scope :users do
scope do param :id, type: Dry::Types["strict.int"]
def get
operations[:find_users].call(id: id)
end
end
end
end
client = MyClient.new user: "andrew", token: "f982j23"
client.operations[:find_user].call(id: 1)
client.users[1].get