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
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 49 50 |
# File 'lib/ya/api/direct/client.rb', line 22 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.
15 16 17 |
# File 'lib/ya/api/direct/client.rb', line 15 def @cache_timestamp end |
#gateway ⇒ Object (readonly)
Returns the value of attribute gateway.
15 16 17 |
# File 'lib/ya/api/direct/client.rb', line 15 def gateway @gateway end |
#units_data ⇒ Object (readonly)
Returns the value of attribute units_data.
15 16 17 |
# File 'lib/ya/api/direct/client.rb', line 15 def units_data @units_data end |
#v4 ⇒ Object (readonly)
Returns the value of attribute v4.
15 16 17 |
# File 'lib/ya/api/direct/client.rb', line 15 def v4 @v4 end |
#v5 ⇒ Object (readonly)
Returns the value of attribute v5.
15 16 17 |
# File 'lib/ya/api/direct/client.rb', line 15 def v5 @v5 end |
Instance Method Details
#start_cache! ⇒ String
Start caching. Executed automatically, if @congif is true.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ya/api/direct/client.rb', line 63 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'] update_units_data result[:units_data] end @cache_timestamp = Time.parse() @cache_timestamp end |
#update_units_data(units_data = {}) ⇒ Hash
Update units data.
56 57 58 |
# File 'lib/ya/api/direct/client.rb', line 56 def update_units_data(units_data = {}) @units_data.merge! units_data end |