Class: Adzerk::Client
Constant Summary collapse
- DEFAULTS =
{ :host => ENV["ADZERK_API_HOST"] || 'https://api.adzerk.net/v1/', :header => 'X-Adzerk-ApiKey' }
Instance Attribute Summary collapse
-
#ad_types ⇒ Object
readonly
Returns the value of attribute ad_types.
-
#advertisers ⇒ Object
readonly
Returns the value of attribute advertisers.
-
#campaigns ⇒ Object
readonly
Returns the value of attribute campaigns.
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#channel_site_maps ⇒ Object
readonly
Returns the value of attribute channel_site_maps.
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#creative_maps ⇒ Object
readonly
Returns the value of attribute creative_maps.
-
#creatives ⇒ Object
readonly
Returns the value of attribute creatives.
-
#flights ⇒ Object
readonly
Returns the value of attribute flights.
-
#geotargetings ⇒ Object
readonly
Returns the value of attribute geotargetings.
-
#invitations ⇒ Object
readonly
Returns the value of attribute invitations.
-
#logins ⇒ Object
readonly
Returns the value of attribute logins.
-
#priorities ⇒ Object
readonly
Returns the value of attribute priorities.
-
#publishers ⇒ Object
readonly
Returns the value of attribute publishers.
-
#reports ⇒ Object
readonly
Returns the value of attribute reports.
-
#sites ⇒ Object
readonly
Returns the value of attribute sites.
-
#sitezonetargetings ⇒ Object
readonly
Returns the value of attribute sitezonetargetings.
-
#zones ⇒ Object
readonly
Returns the value of attribute zones.
Instance Method Summary collapse
- #create_creative(data = {}, image_path = '') ⇒ Object
- #get_request(url) ⇒ Object
-
#initialize(key, opts = {}) ⇒ Client
constructor
A new instance of Client.
- #post_request(url, data) ⇒ Object
- #put_request(url, data) ⇒ Object
- #send_request(request, uri) ⇒ Object
- #upload_creative(id, image_path) ⇒ Object
Methods included from Util
#camelize_data, #parse_response, #uncamelize_data
Constructor Details
#initialize(key, opts = {}) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/adzerk/client.rb', line 16 def initialize(key, opts = {}) @api_key = key @config = DEFAULTS.merge!(opts) @logins = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'login') @sites = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'site') @ad_types = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'adtypes', :subendpoint => 'channel', :datakey => 'adtype') @flights = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'flight') @zones = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'zone') @campaigns = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'campaign') @channels = Adzerk::ApiEndpoint.new(:client => self, :endpoint => 'channel') @priorities = Adzerk::Priority.new(:client => self, :endpoint => 'priority') @advertisers = Adzerk::Advertiser.new(:client => self, :endpoint => 'advertiser') @publishers = Adzerk::Publisher.new(:client => self, :endpoint => 'publisher') @creatives = Adzerk::Creative.new(:client => self, :endpoint => 'creative') @creative_maps = Adzerk::CreativeMap.new(:client => self) @invitations = Adzerk::Invitation.new(:client => self) @reports = Adzerk::Reporting.new(:client => self) @channel_site_maps = Adzerk::ChannelSiteMap.new(:client => self) @geotargetings = Adzerk::GeoTargeting.new(:client => self, :endpoint => 'geotargeting') @sitezonetargetings = Adzerk::SiteZoneTargeting.new(:client => self, :endpoint => 'sitezone') @categories = Adzerk::Category.new(:client => self, :endpoint => 'category') end |
Instance Attribute Details
#ad_types ⇒ Object (readonly)
Returns the value of attribute ad_types.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def ad_types @ad_types end |
#advertisers ⇒ Object (readonly)
Returns the value of attribute advertisers.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def advertisers @advertisers end |
#campaigns ⇒ Object (readonly)
Returns the value of attribute campaigns.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def campaigns @campaigns end |
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def categories @categories end |
#channel_site_maps ⇒ Object (readonly)
Returns the value of attribute channel_site_maps.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def channel_site_maps @channel_site_maps end |
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def channels @channels end |
#creative_maps ⇒ Object (readonly)
Returns the value of attribute creative_maps.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def creative_maps @creative_maps end |
#creatives ⇒ Object (readonly)
Returns the value of attribute creatives.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def creatives @creatives end |
#flights ⇒ Object (readonly)
Returns the value of attribute flights.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def flights @flights end |
#geotargetings ⇒ Object (readonly)
Returns the value of attribute geotargetings.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def geotargetings @geotargetings end |
#invitations ⇒ Object (readonly)
Returns the value of attribute invitations.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def invitations @invitations end |
#logins ⇒ Object (readonly)
Returns the value of attribute logins.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def logins @logins end |
#priorities ⇒ Object (readonly)
Returns the value of attribute priorities.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def priorities @priorities end |
#publishers ⇒ Object (readonly)
Returns the value of attribute publishers.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def publishers @publishers end |
#reports ⇒ Object (readonly)
Returns the value of attribute reports.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def reports @reports end |
#sites ⇒ Object (readonly)
Returns the value of attribute sites.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def sites @sites end |
#sitezonetargetings ⇒ Object (readonly)
Returns the value of attribute sitezonetargetings.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def sitezonetargetings @sitezonetargetings end |
#zones ⇒ Object (readonly)
Returns the value of attribute zones.
6 7 8 |
# File 'lib/adzerk/client.rb', line 6 def zones @zones end |
Instance Method Details
#create_creative(data = {}, image_path = '') ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/adzerk/client.rb', line 63 def create_creative(data={}, image_path='') response = RestClient.post(@config[:host] + 'creative', {:creative => camelize_data(data).to_json}, :X_Adzerk_ApiKey => @api_key, :accept => :json) response = upload_creative(JSON.parse(response)["Id"], image_path) unless image_path.empty? response end |
#get_request(url) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/adzerk/client.rb', line 40 def get_request(url) uri = URI.parse(@config[:host] + url) request = Net::HTTP::Get.new(uri.request_uri) request.add_field(@config[:header], @api_key) send_request(request, uri) end |
#post_request(url, data) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/adzerk/client.rb', line 47 def post_request(url, data) uri = URI.parse(@config[:host] + url) request = Net::HTTP::Post.new(uri.request_uri) request.add_field(@config[:header], @api_key) request.set_form_data(data) send_request(request, uri) end |
#put_request(url, data) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/adzerk/client.rb', line 55 def put_request(url, data) uri = URI.parse(@config[:host] + url) request = Net::HTTP::Put.new(uri.request_uri) request.add_field(@config[:header], @api_key) request.set_form_data(data) send_request(request, uri) end |
#send_request(request, uri) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/adzerk/client.rb', line 80 def send_request(request, uri) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == 'https' response = http.request(request) if response.kind_of? Net::HTTPClientError error_response = JSON.parse(response.body) raise Adzerk::ApiError.new(error_response["message"]) end response end |
#upload_creative(id, image_path) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/adzerk/client.rb', line 72 def upload_creative(id, image_path) image = File.new(image_path, 'rb') RestClient.post(@config[:host] + 'creative/' + id.to_s + '/upload', {:image => image}, "X-Adzerk-ApiKey" => @api_key, :accept => :mime) end |