Class: Ya::Direct::Gateway
- Inherits:
-
Object
- Object
- Ya::Direct::Gateway
- Defined in:
- lib/ya_direct_api/gateway.rb
Constant Summary collapse
- URLS =
{ production: "https://soap.direct.yandex.ru/json-api/v4/", staging: "https://soap.direct.yandex.ru/json-api/v4/", development: "https://api-sandbox.direct.yandex.ru/json-api/v4/" }
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #get_data(method, params) ⇒ Object
-
#initialize(env, config) ⇒ Gateway
constructor
A new instance of Gateway.
- #request(method, params) ⇒ Object
- #request_options(method, params) ⇒ Object
- #validate_response!(response) ⇒ Object
Constructor Details
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/ya_direct_api/gateway.rb', line 4 def url @url end |
Instance Method Details
#get_data(method, params) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/ya_direct_api/gateway.rb', line 45 def get_data(method, params) response = request(method, params) parsed_response = JSON.parse(response) validate_response!(parsed_response) parsed_response end |
#request(method, params) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ya_direct_api/gateway.rb', line 27 def request(method, params) url = URI.parse(@url) request = Net::HTTP::Post.new(url.path, initheader = {'Content-Type' =>'application/json'}) request.body = (method, params).to_json http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE response = http.request(request) if response.kind_of? Net::HTTPSuccess return response.body else raise response.inspect end end |
#request_options(method, params) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/ya_direct_api/gateway.rb', line 17 def (method, params) { locale: @config[:locale], login: @config[:login], application_id: @config[:app_id], token: @config[:token], method: method }.merge(params) end |