Direct::API::V5

Ruby wrapper for Yandex Direct API V5.
Installation
Add this line to your application's Gemfile:
gem 'direct-api-v5'
And then execute:
$ bundle
Or install it yourself as:
$ gem install direct-api-v5
Usage
Settings
- Load settings from YML file
Direct::API::V5.load_settings('config/yandex_direct_api.yml')
production:
host: api.direct.yandex.com
auth_token: token_string
client_login: login_string
language: ru
development:
host: api-sandbox.direct.yandex.com
auth_token: token_string
client_login: login_string
language: ru
Direct::API::V5.configure do |config|
config.host = 'api.direct.yandex.com'
config.auth_token = 'token_string'
config.client_login = 'login_string'
config.language = 'ru'
end
Create client
api = Direct::API::V5.client
You can set client login (if advertising agency)
api = Direct::API::V5.client(client_login: 'login_string')
Also you can overwrite any default settings:
api = Direct::API::V5.client(host: 'api.direct.yandex.com', auth_token: 'token')
Call methods
Base structure:
api.service_name.method(params)
For example:
response = api.campaigns.get(
fields: [:id, :name],
criteria: { states: %w(ON) },
page: { limit: 100, offset: 200 }
)
response.error?
response.result
response.request_id
response.units.spent
response.units.available
response.units.daily_limit
response.units.raw
If API return error:
response.error?
response.error.code
response.error.message
response.error.details
response.error.to_h
Contributing
- Fork it ( https://github.com/hrom512/direct-api-v5/fork )
- Create your feature branch (
git checkout -b my-new-feature
)
- Commit your changes (
git commit -am 'Add some feature'
)
- Push to the branch (
git push origin my-new-feature
)
- Create a new Pull Request