Class: Ya::API::Direct::Client
- Inherits:
-
Object
- Object
- Ya::API::Direct::Client
- Defined in:
- lib/ya/api/direct/client.rb
Overview
Yandex Direct API client class
Instance Attribute Summary collapse
-
#cache_timestamp ⇒ Object
readonly
Returns the value of attribute cache_timestamp.
-
#gateway ⇒ Object
readonly
Returns the value of attribute gateway.
-
#units_data ⇒ Object
readonly
Returns the value of attribute units_data.
-
#v4 ⇒ Object
readonly
Returns the value of attribute v4.
-
#v5 ⇒ Object
readonly
Returns the value of attribute v5.
Instance Method Summary collapse
-
#initialize(config = {}) {|_self| ... } ⇒ Ya::API::Direct::Client
constructor
Initializes a new Client object.
-
#start_cache! ⇒ String
Start caching.
-
#update_units_data(units_data = {}) ⇒ Hash
Update units data.
Constructor Details
#initialize(config = {}) {|_self| ... } ⇒ Ya::API::Direct::Client
Initializes a new Client object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ya/api/direct/client.rb', line 20 def initialize(config = {}) @config = { token: nil, app_id: nil, login: '', locale: 'en', mode: :sandbox, format: :json, cache: true, api: :v5, ssl: true }.merge(config) @units_data = { just_used: nil, units_left: nil, units_limit: nil } raise "Token can't be empty" if @config[:token].nil? raise "Allowed Yandex Direct API versions are #{AllowedVersions}" unless AllowedAPIVersions.include? @config[:api] @gateway = Ya::API::Direct::Gateway.new @config init_v4 init_v5 start_cache! if @config[:cache] yield self if block_given? end |
Instance Attribute Details
#cache_timestamp ⇒ Object (readonly)
Returns the value of attribute cache_timestamp.
13 14 15 |
# File 'lib/ya/api/direct/client.rb', line 13 def @cache_timestamp end |
#gateway ⇒ Object (readonly)
Returns the value of attribute gateway.
13 14 15 |
# File 'lib/ya/api/direct/client.rb', line 13 def gateway @gateway end |
#units_data ⇒ Object (readonly)
Returns the value of attribute units_data.
13 14 15 |
# File 'lib/ya/api/direct/client.rb', line 13 def units_data @units_data end |
#v4 ⇒ Object (readonly)
Returns the value of attribute v4.
13 14 15 |
# File 'lib/ya/api/direct/client.rb', line 13 def v4 @v4 end |
#v5 ⇒ Object (readonly)
Returns the value of attribute v5.
13 14 15 |
# File 'lib/ya/api/direct/client.rb', line 13 def v5 @v5 end |
Instance Method Details
#start_cache! ⇒ String
Start caching. Executed automatically, if @congif is true.
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ya/api/direct/client.rb', line 61 def start_cache! case @config[:api] when :v4 result = @gateway.request("GetChanges", {}, nil, :v4live) = result[:data]['data']['Timestamp'] when :v5 result = @gateway.request("checkDictionaries", {}, "changes", :v5) = result[:data]['result']['Timestamp'] end @cache_timestamp = Time.parse() update_units_data result[:units_data] @cache_timestamp end |
#update_units_data(units_data = {}) ⇒ Hash
Update units data.
54 55 56 |
# File 'lib/ya/api/direct/client.rb', line 54 def update_units_data(units_data = {}) @units_data.merge! units_data end |