Naver Searchad API
A Client GEM for Naver Searchad API
Alpha
This library is in Alpha. We will make an effort to support the library, but we reserve the right to make incompatible changes when necessary.
Installation
Add this line to your application's Gemfile:
gem 'naver-searchad-api'
And then execute:
$ bundle
Or install it yourself as:
$ gem install naver-searchad-api
Compatibility
naver-searchad-api supports the following Ruby implementations:
- MRI 2.0
- MRI 2.1
- MRI 2.2
- MRI 2.3
Usage
Basic usage
To use an API, instantiate the service. For example to use the Campaign API:
require 'naver/searchad/api/campaign/service'
require 'naver/searchad/api/auth'
Campaign = Naver::Searchad::Api::Campaign # Alias the module
campaign = Campaign::Service.new
campaign.authorization = Naver::Searchad::Api::Auth.get_application_default # See Below Authorization
# Read all campaigns (with camelCase response)
campaign.list_campaigns(options: { decode_snake_case: false }) do |res, err|
puts res
end
# Read campaigns by ids
campaign.list_campaigns_by_ids(['campaign_id_1', 'campaign_id_2']) do |res, err|
puts res
end
# Create a campaign
campaign = { ..... }
campaign.create_campaign(campaign) do |res, err|
puts res
end
# Delete
campaign_id = ... # A campaign id to delete
campaign.delete_campaign(campaign_id)
Naming conventions vs JSON representation
Object properties in the ruby client use the standard ruby convention for naming -- snake_case. This differs from the underlying JSON representation which typically uses camelCase for properties.
Callbacks
A block can be specified when making calls. If present, the block will be called with the result or error, rather than returning the result from the call or raising the error. Example:
# Read a campaign
campaign.get_campaign('campaign_id_1') do |res, err|
if err
# Handle error
else
# Handle response
end
end
Authorization
Naver Searchad API authorization is used to authorize applications.
Authorization using environment variables
The Naver Searchad API Auth also supports authorization via environment variables if you do not want to check in developer credentials or private keys. Simply set the following variables for your application:
NAVER_API_KEY="YOUR NAVER DEVELOPER API KEY"
NAVER_API_SECRET="YOUR NAVER DEVELOPER API SECRET"
NAVER_API_CLIENT_ID="YOUR NAVER DEVELOPER CLIENT ID"
Logging
The client includes a Logger
instance that can be used to capture debugging information.
To set the logging level for the client:
Naver::Searchad::Api.logger.level = Logger::DEBUG
When running in a Rails environment, the client will default to using ::Rails.logger
. If you
prefer to use a separate logger instance for API calls, this can be changed via one of two ways.
The first is to provide a new logger instance:
Naver::Searchad::Api.logger = Logger.new(STDERR)
License
This library is licensed under Apache 2.0. Full license text is available in LICENSE.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/forward3d/naver-searchad-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
We encourage contributors to follow Bozhidar's ruby style guide in this project.
Pull requests (with tests) are appreciated. Please help with:
- Reporting bugs
- Suggesting features
- Writing or improving documentation
- Fixing typos
- Cleaning whitespace
- Refactoring code
- Adding tests
If you report a bug and don't include a fix, please include a failing test.