outbrain-api 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/outbrain/api.rb +3 -0
 - data/lib/outbrain/api/campaign_report.rb +17 -0
 - data/lib/outbrain/api/marketer.rb +6 -0
 - data/lib/outbrain/api/publisher_report.rb +18 -0
 - data/lib/outbrain/api/report.rb +13 -0
 - data/lib/outbrain/api/version.rb +1 -1
 - data/lib/outbrain/request.rb +10 -4
 - metadata +5 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1432fa565760986e9847e2626c845e83a74f9213
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ffb584a218ea82418e194929ad6c2794b749364a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 164939127bb86b6cf321dae9bf5dc507f76c442d0496ed841b3341f729bfd41cbd105de88ebc4b9c95c8ef8f32ff79324f54641825a8d87a1c22d1573e1f6046
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 62d1c73188c94333a0089a4bfeaed64171201051eaf2dda7bc6286dfd0cc2e59fd8a3a9487d0e39d0bd4257ae3892079a8b834f963ce340a01262bdd441f9b51
         
     | 
    
        data/lib/outbrain/api.rb
    CHANGED
    
    | 
         @@ -9,6 +9,9 @@ require "outbrain/request" 
     | 
|
| 
       9 
9 
     | 
    
         
             
            # models
         
     | 
| 
       10 
10 
     | 
    
         
             
            require "outbrain/api/marketer"
         
     | 
| 
       11 
11 
     | 
    
         
             
            require "outbrain/api/campaign"
         
     | 
| 
      
 12 
     | 
    
         
            +
            require "outbrain/api/budget"
         
     | 
| 
      
 13 
     | 
    
         
            +
            require "outbrain/api/campaign_report"
         
     | 
| 
      
 14 
     | 
    
         
            +
            require "outbrain/api/publisher_report"
         
     | 
| 
       12 
15 
     | 
    
         | 
| 
       13 
16 
     | 
    
         
             
            module Outbrain
         
     | 
| 
       14 
17 
     | 
    
         
             
              HEADER_AUTH_KEY = 'OB-TOKEN-V1'
         
     | 
| 
         @@ -0,0 +1,17 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'outbrain/api/report'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Outbrain
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Api
         
     | 
| 
      
 5 
     | 
    
         
            +
                class CampaignReport < Report
         
     | 
| 
      
 6 
     | 
    
         
            +
                  PATH = 'performanceByCampaign'
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                  def self.path(marketer_id)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    "marketers/#{marketer_id}/#{PATH}"
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  def self.where(options = {})
         
     | 
| 
      
 13 
     | 
    
         
            +
                    super(options.merge({path: self.path(options.fetch(:marketer_id))}))
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,5 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require "outbrain/api/publisher"
         
     | 
| 
       2 
2 
     | 
    
         
             
            require "outbrain/api/budget"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require "outbrain/api/report"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "outbrain/api/campaign_report"
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
       4 
6 
     | 
    
         
             
            module Outbrain
         
     | 
| 
       5 
7 
     | 
    
         
             
              module Api
         
     | 
| 
         @@ -19,6 +21,10 @@ module Outbrain 
     | 
|
| 
       19 
21 
     | 
    
         
             
                  def budgets
         
     | 
| 
       20 
22 
     | 
    
         
             
                    Budget.find_by(marketer_id: id)
         
     | 
| 
       21 
23 
     | 
    
         
             
                  end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  def campaign_reports(options = {})
         
     | 
| 
      
 26 
     | 
    
         
            +
                    CampaignReport.where(options.merge({marketer_id: id}))
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
       22 
28 
     | 
    
         
             
                end
         
     | 
| 
       23 
29 
     | 
    
         
             
              end
         
     | 
| 
       24 
30 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,18 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'outbrain/api/report'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Outbrain
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Api
         
     | 
| 
      
 5 
     | 
    
         
            +
                class PublisherReport < Report
         
     | 
| 
      
 6 
     | 
    
         
            +
                  PATH = 'performanceByPublisher'
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                  def self.path(campaign_id)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    "campaigns/#{campaign_id}/#{PATH}"
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  def self.where(options = {})
         
     | 
| 
      
 13 
     | 
    
         
            +
                    super(options.merge({path: self.path(options.fetch(:campaign_id))}))
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
            end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
         @@ -0,0 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Outbrain
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Api
         
     | 
| 
      
 3 
     | 
    
         
            +
                class Report < Base
         
     | 
| 
      
 4 
     | 
    
         
            +
                  REPORT_PARAMETERS = [:from, :to, :limit, :offset, :sort]
         
     | 
| 
      
 5 
     | 
    
         
            +
                  RESOURCE_NAME = 'details'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                  def self.where(options = {})
         
     | 
| 
      
 8 
     | 
    
         
            +
                    report_options = options.select{|option, v| REPORT_PARAMETERS.include?(option) && !v.nil?}        
         
     | 
| 
      
 9 
     | 
    
         
            +
                    Request.where(options.fetch(:path), report_options, { as: self, resource_name: RESOURCE_NAME })
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/outbrain/api/version.rb
    CHANGED
    
    
    
        data/lib/outbrain/request.rb
    CHANGED
    
    | 
         @@ -1,15 +1,21 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Outbrain
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Request < Config
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
3 
     | 
    
         
             
                def self.where(resource_path, query={}, options={})
         
     | 
| 
       5 
     | 
    
         
            -
                   
     | 
| 
      
 4 
     | 
    
         
            +
                  request_path = "/amplify/#{api_version}/#{resource_path}"
         
     | 
| 
      
 5 
     | 
    
         
            +
                  query_string = query.map{|k,v| "#{k}=#{v}"}.join("&")
         
     | 
| 
      
 6 
     | 
    
         
            +
                  request_path = request_path + '?' + query_string unless query_string.empty?
         
     | 
| 
      
 7 
     | 
    
         
            +
                  response = api.get(request_path)
         
     | 
| 
       6 
8 
     | 
    
         
             
                  resource_name = options.fetch(:resource_name, resource_path)
         
     | 
| 
       7 
9 
     | 
    
         
             
                  json_body = JSON.parse(response.body) # catch and raise proper api error
         
     | 
| 
       8 
10 
     | 
    
         | 
| 
       9 
11 
     | 
    
         
             
                  fail InvalidOption 'requires an as option' unless options[:as]
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                   
     | 
| 
       12 
     | 
    
         
            -
                     
     | 
| 
      
 13 
     | 
    
         
            +
                  if response.status == 200
         
     | 
| 
      
 14 
     | 
    
         
            +
                    json_body[resource_name].map do |obj|
         
     | 
| 
      
 15 
     | 
    
         
            +
                      options[:as].new(obj)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    end
         
     | 
| 
      
 17 
     | 
    
         
            +
                  else
         
     | 
| 
      
 18 
     | 
    
         
            +
                    [json_body]
         
     | 
| 
       13 
19 
     | 
    
         
             
                  end
         
     | 
| 
       14 
20 
     | 
    
         
             
                end
         
     | 
| 
       15 
21 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: outbrain-api
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.6
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Nick Blanchet
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2016-04- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-04-19 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: faraday
         
     | 
| 
         @@ -113,10 +113,13 @@ files: 
     | 
|
| 
       113 
113 
     | 
    
         
             
            - lib/outbrain/api.rb
         
     | 
| 
       114 
114 
     | 
    
         
             
            - lib/outbrain/api/budget.rb
         
     | 
| 
       115 
115 
     | 
    
         
             
            - lib/outbrain/api/campaign.rb
         
     | 
| 
      
 116 
     | 
    
         
            +
            - lib/outbrain/api/campaign_report.rb
         
     | 
| 
       116 
117 
     | 
    
         
             
            - lib/outbrain/api/config.rb
         
     | 
| 
       117 
118 
     | 
    
         
             
            - lib/outbrain/api/errors.rb
         
     | 
| 
       118 
119 
     | 
    
         
             
            - lib/outbrain/api/marketer.rb
         
     | 
| 
       119 
120 
     | 
    
         
             
            - lib/outbrain/api/publisher.rb
         
     | 
| 
      
 121 
     | 
    
         
            +
            - lib/outbrain/api/publisher_report.rb
         
     | 
| 
      
 122 
     | 
    
         
            +
            - lib/outbrain/api/report.rb
         
     | 
| 
       120 
123 
     | 
    
         
             
            - lib/outbrain/api/version.rb
         
     | 
| 
       121 
124 
     | 
    
         
             
            - lib/outbrain/base.rb
         
     | 
| 
       122 
125 
     | 
    
         
             
            - lib/outbrain/config.rb
         
     |