class YandexDirect::Client

Attributes

app_id[RW]
available_units[R]
login[RW]
test[RW]
token[RW]

Public Class Methods

new(options = {}) { |self| ... } click to toggle source
# File lib/yandex_direct.rb, line 19
def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end

  @url = 'https://api.direct.yandex.ru/json-api/v4/'
  @url_live = 'https://api.direct.yandex.ru/live/v4/json/'

  yield(self) if block_given?
end

Public Instance Methods

banners_tags(param) click to toggle source
# File lib/yandex_direct.rb, line 62
def banners_tags(param)
  request_live('GetBannersTags', param)
end
campaigns_tags(param) click to toggle source
# File lib/yandex_direct.rb, line 54
def campaigns_tags(param)
  request_live('GetCampaignsTags', param)
end
create_new_wordstat_report(param = nil) click to toggle source
# File lib/yandex_direct.rb, line 30
def create_new_wordstat_report(param = nil)
  param ||= { Phrases: ['синтепон'], GeoID: [213] }
  request('CreateNewWordstatReport', param)['data']
end
delete_wordstat_report(param) click to toggle source
# File lib/yandex_direct.rb, line 35
def delete_wordstat_report(param)
  request('DeleteWordstatReport', param)
end
ping_api() click to toggle source
# File lib/yandex_direct.rb, line 66
def ping_api
  request('PingAPI')
end
update_banners_tags(param) click to toggle source
# File lib/yandex_direct.rb, line 58
def update_banners_tags(param)
  request_live('UpdateBannersTags', param)
end
update_campaigns_tags(param) click to toggle source
# File lib/yandex_direct.rb, line 50
def update_campaigns_tags(param)
  request_live('UpdateCampaignsTags', param)
end
wordstat_report(param) click to toggle source
# File lib/yandex_direct.rb, line 39
def wordstat_report(param)
  result = request('GetWordstatReport', param)
  raise(YandexDirect::BlankDataError, 'Blank data') if result['data'].empty?

  result
end
wordstat_report_list() click to toggle source
# File lib/yandex_direct.rb, line 46
def wordstat_report_list
  request('GetWordstatReportList')
end

Private Instance Methods

request(method, param = nil) click to toggle source
# File lib/yandex_direct.rb, line 86
def request(method, param = nil)
  request_v4(@url, method, param)
end
request_live(method, param = nil) click to toggle source
# File lib/yandex_direct.rb, line 90
def request_live(method, param = nil)
  request_v4(@url_live, method, param)
end
request_v4(url, method, param) click to toggle source
# File lib/yandex_direct.rb, line 72
def request_v4(url, method, param)
  result = HTTP.post(url, json: {
                       method: method,
                       token: @token,
                       locale: 'ru',
                       param: param
                     }).parse

  raise(YandexDirect::AuthorizationError, "#{result['error_str']}: #{result['error_detail']}") if result['error_code'] == 53
  raise(YandexDirect::Error, "[#{result['error_code']}] #{result['error_str']}: #{result['error_detail']}") if result.key?('error_code')

  result
end