
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Accessing Yandex API and work with campaigns and statistics
Just in console
gem install yandex-api-direct
Or put into Gemfile
gem "yandex-api-direct"
and somewhere before use (not rails - they will require gem automaticaly)
require "yandex-api-direct"
Setup your config values by calling YandexApiDirect.config = {}
YandexApiDirect.config = {
locale: "en"
application_id: "YOUR APPLICATION ID"
login: "FILL LOGIN OF USER"
access_token: "FILL ACCESS TOKEN FOR USER"
}
Get application_id by registering your application at https://oauth.yandex.com/client/new (full doc at: http://api.yandex.com/oauth/doc/dg/tasks/register-client.xml)
If you need to get Oauth token you will also need application password (also listed on registration page).
You can access Main classes: Client, Campaign, CampaignParam, CampaignStats
Main classes are inherited from Hashr and includes YandexObject This combination will provide very easy acces to all returned values from API.
# Find some objects:
campaigns = YandexApiDirect::Campaign.find
# you got [ <Campaign:..>, ... ] and choose first one
campaign = campaigns.first
# then you can ask for something
campaign.name #=> "Campaign"
campaign.campaign_id #=> 123456
campaign.clicks #=> 123
Arguments from api is hash, this hash is saved by hashr directly into instance.
Keys from API are underscored for using as normal methods not campaign.Name
instead of this use: campaign.name
Instance is still Hash, you can do all stuf like with normal hash.
#you can pass arguments to find as hash: [GetClientsList](http://api.yandex.com/direct/doc/reference/GetClientsList.xml)
YandexApiDirect::Client.find
#=> [ <Client:..>, ... ]
#you can pass argument as array of logins (optional for agencies): [GetCampaignsList](http://api.yandex.com/direct/doc/reference/GetCampaignsList.xml)
YandexApiDirect::Campaign.find
#=> [ <Campaign:..>, ... ]
#you can pass arguments to find as hash: [GetCampaignParams](http://api.yandex.com/direct/doc/reference/GetCampaignParams.xml)
YandexApiDirect::CampaignParams.find
#=> [ <CampaignParams:..>, ... ]
#you can pass arguments to find as hash: [GetSummaryStat](http://api.yandex.com/direct/doc/reference/GetSummaryStat.xml)
YandexApiDirect::CampaignStats.find
#=> [ <CampaignStats:..>, ... ]
All arguments you will pass into params are automatically camelized, because Yandex API takes only Camelcased attribute names:
# Example:
campaign.campaign_stats start_date: Date.today
# will transform inside of method into
{ :"StartDate" => Date.today }
If you will implement your own methods, you can use built in method in YandexObject camelize_keys(hash)
Yandex uses this hierarchy and gem follows it
#get first Client
client = Client.find.first
#get all client campaign
campaigns = client.campaigns
campaign = campaigns.first
#get campaign statistics
campaign.campaign_stats start_date: Date.today-8, end_date: Date.today-1
#=> [<CampaingStats:..>, ...]
#get campaign params
campaign.campaign_params
#=> <CampaingParams:... > - not array but directly one object (campaign can have only one params!)
There is a class YandexApiDirect::Generic which provides class method get has two parameters
YandexApiDirect::Generic.get "get_clients_info"
#=> will return hash containing client info (Only one item returned)
YandexApiDirect::Generic.get "get_clients_list"
#=> will return array containing hashes of client info (More items returned)
By this you can call all methods without writing more code.
Yandex api allows you to use sandbox for testing purposes: Yandex Sandbox
In your test helper write down
YandexApiDirect.url "sandbox" #or if you like symbols :sandbox :-)
#or for directly saying to use production
YandexApiDirect.url "production" #or if you like symbols :production :-)
This will set url of Yandex to sandbox or production. If you will not set url it will use ENV['RACK_ENV'] or ENV['RAILS_ENV'] == "test" it will use "sandbox" as default, all other environments (including development) will have sa default setted "production"
Copyright (c) 2012 Ondrej Bartas. See LICENSE.txt for further details.
FAQs
Unknown package
We found that yandex-api-direct demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.