ya-api-direct
A Ruby interface to Yandex Direct API
Installation
Add this line to your application's Gemfile:
gem 'ya-api-direct'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ya_direct_api
Test with rake:
$ rake
Usage
OAuth2 Yandex token is needed. Use omniauth-yandex to receive it. Install it according by following manual: Rails Authentication with OAuth 2.0 and OmniAuth.
Call methods of Yandex Direct API 5:
request = {
"SelectionCriteria" => {
"Types" => ["TEXT_CAMPAIGN"]
},
"FieldNames" => ["Id", "Name"],
"TextCampaignFieldNames" => ["BiddingStrategy"]
}
@direct = Ya::API::Direct::Client.new({ token: Token })
json = direct.campaigns.get request
Call methods from versions 4 and 4 Live:
@direct = Ya::API::Direct::Client.new({ token: Token })
json = direct.v4.GetCampaignsList []
All names of controllers and methods are equal to ones from Direct API help. 4 vs 4 Live is autodetected.
Caching
By default the client class sends request to clients. You can avoid it by turning this option off, like this:
@direct = Ya::API::Direct::Client.new({ token: Token, cache: false })
Check Yandex manuals for more info on caching.
Date returned with first call of caching method is stored in cache_timestamp
property.
Units data
Units data of last request is stored in units_data
property. There're 3 keys in this hash:
just_used
units_left
units_limit
Useful links
Contributing
- Fork it ( http://github.com/rikkimongoose/ya-api-direct/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 new Pull Request