class YandexWidget::Requests

Constants

BASE_URL

Public Class Methods

new(path, idempotence_key = nil, params: {}) click to toggle source
# File lib/yandex_widget/requests.rb, line 5
def initialize(path, idempotence_key = nil, params: {})
  @url = BASE_URL + path
  @idempotence_key = idempotence_key
  @params = params
end

Public Instance Methods

init_client() click to toggle source
# File lib/yandex_widget/requests.rb, line 11
def init_client
  HTTParty.post(@url, body: @params.to_json, headers: default_headers,
                      basic_auth: auth, format: :json).parsed_response
end
request_info() click to toggle source
# File lib/yandex_widget/requests.rb, line 16
def request_info
  HTTParty.get(@url, basic_auth: auth, format: :json).parsed_response
end
set_status() click to toggle source
# File lib/yandex_widget/requests.rb, line 20
def set_status
  HTTParty.post(@url, body: @params.to_json, headers: default_headers,
                      basic_auth: auth, format: :json)
end

Private Instance Methods

auth() click to toggle source
# File lib/yandex_widget/requests.rb, line 34
def auth
  {
    username: YandexWidget.configuration.store_id,
    password: YandexWidget.configuration.secret_key
  }
end
default_headers() click to toggle source
# File lib/yandex_widget/requests.rb, line 27
def default_headers
  {
    'Idempotence-Key': @idempotence_key,
    'Content-Type': 'application/json'
  }
end