Class: Yookassa::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yookassa/client.rb

Constant Summary collapse

API_URL =
"https://api.yookassa.ru/v3/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shop_id:, api_key:) ⇒ Client

Returns a new instance of Client.



14
15
16
# File 'lib/yookassa/client.rb', line 14

def initialize(shop_id:, api_key:)
  @http = HTTP.basic_auth(user: shop_id, pass: api_key).headers(accept: "application/json")
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



12
13
14
# File 'lib/yookassa/client.rb', line 12

def http
  @http
end

Instance Method Details

#get(endpoint, query: {}) ⇒ Object



26
27
28
# File 'lib/yookassa/client.rb', line 26

def get(endpoint, query: {})
  api_call { http.get("#{API_URL}#{endpoint}", params: query) }
end

#paymentsObject



18
19
20
# File 'lib/yookassa/client.rb', line 18

def payments
  @payments ||= Payments.new(self)
end

#post(endpoint, idempotency_key:, payload: {}) ⇒ Object



30
31
32
# File 'lib/yookassa/client.rb', line 30

def post(endpoint, idempotency_key:, payload: {})
  api_call { http.headers("Idempotence-Key" => idempotency_key).post("#{API_URL}#{endpoint}", json: payload) }
end

#refundsObject



22
23
24
# File 'lib/yookassa/client.rb', line 22

def refunds
  @refunds ||= Refunds.new(self)
end