Class: YandexOffers::Request

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/yandex_offers/request.rb

Class Method Summary collapse

Class Method Details

.headersObject



26
27
28
# File 'lib/yandex_offers/request.rb', line 26

def headers
  @headers ||= { "Content-Type" => "application/json", "Accept" => "application/json" }
end

.post(url, body) ⇒ Object



7
8
9
10
11
12
# File 'lib/yandex_offers/request.rb', line 7

def post(url, body)
  options = {}
  options[:format] = :json
  options[:body] = body
  HTTParty.post("#{YandexOffers.configuration.base_url}#{url}", options).parsed_response
end

.post_with_authorization(url, body) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/yandex_offers/request.rb', line 14

def post_with_authorization(url, body)
  options = {}
  options[:format] = :json
  options[:body] = body.to_json
  options[:headers] = self.headers.merge({"Authorization" => "Bearer #{self.token}"})
  HTTParty.post("#{YandexOffers.configuration.base_url}#{url}", options).parsed_response
end

.tokenObject



22
23
24
# File 'lib/yandex_offers/request.rb', line 22

def token
  @token ||= YandexOffers::Authorization.new.get_token
end