rubicon-api-client 0.1.1
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 +7 -0
- data/lib/rubicon-api-client.rb +91 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 438e1e4f49ca4ffad2331ef9dec1ec7ee6eb809f
|
4
|
+
data.tar.gz: 9e083a8de15c2810bf53e1091e0bfaa89a30acfc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a9f49960a9cf9ce65ca28021c24ecd0ecf808e34679c6ceda02903f28fa10d201d82019c629b16504efd1652b42ccfb8b7fee7a4cf45a96c0b9f6028882565c9
|
7
|
+
data.tar.gz: e06b2fb0e909dc7dfaff2b0c4f6530b9dd0a6116557c479ea36b362910f8409cfacff3e950ff9ac65e08cd4cbafbf3be216784e184cef048468fcc1058bdb832
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/http/digest_auth'
|
4
|
+
module RubiconApiClient
|
5
|
+
class RubiconClient
|
6
|
+
@@host = 'http://api.rubiconproject.com'
|
7
|
+
|
8
|
+
|
9
|
+
def whens
|
10
|
+
['today', 'yesterday', 'this week', 'last week', 'this month', 'last month', 'this year', 'last 7', 'last 30', 'all']
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def initialize(id, key, secret)
|
15
|
+
@id = id
|
16
|
+
@key = key
|
17
|
+
@secret = secret
|
18
|
+
end
|
19
|
+
|
20
|
+
def execute(path)
|
21
|
+
puts path
|
22
|
+
|
23
|
+
uri = URI.parse @@host
|
24
|
+
uri.user = @key
|
25
|
+
uri.password = @secret
|
26
|
+
|
27
|
+
net = Net::HTTP.new uri.host
|
28
|
+
req = Net::HTTP::Get.new path
|
29
|
+
|
30
|
+
res = net.request req
|
31
|
+
|
32
|
+
auth = Net::HTTP::DigestAuth.new.auth_header uri, res['www-authenticate'], 'GET'
|
33
|
+
req = Net::HTTP::Get.new path
|
34
|
+
req.add_field 'Authorization', auth
|
35
|
+
res = net.request req
|
36
|
+
res.read_body
|
37
|
+
end
|
38
|
+
|
39
|
+
def compose_arguments(hash)
|
40
|
+
args = []
|
41
|
+
hash.each_key do |key|
|
42
|
+
hash[key] = [hash[key]] if !hash[key].is_a?(Array)
|
43
|
+
args << "#{key}=#{hash[key].join(',')}" unless hash[key][0] == '' || hash[key][0].nil?
|
44
|
+
end
|
45
|
+
URI.escape '?'+args.join('&')
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_date(date_range_splat)
|
49
|
+
args = {}
|
50
|
+
if whens.include? date_range_splat[0].to_s
|
51
|
+
args['when'] = date_range_splat[0].to_s
|
52
|
+
elsif date_range_splat.length == 2
|
53
|
+
args['start'] = Date.parse(date_range_splat[0].to_s).to_s
|
54
|
+
args['end'] = Date.parse(date_range_splat[0].to_s).to_s
|
55
|
+
end
|
56
|
+
args
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Seller < RubiconClient
|
61
|
+
def zone_performance_report(site_ids='',*date_range)
|
62
|
+
|
63
|
+
args = parse_date date_range
|
64
|
+
|
65
|
+
args['site_id'] = site_ids
|
66
|
+
|
67
|
+
path = "/seller/api/ips/v1/reports/zone/performance/#{@id}/#{compose_arguments args}"
|
68
|
+
execute(path)
|
69
|
+
end
|
70
|
+
|
71
|
+
def ad_hoc_performance_report(dimensions, measures, currency=nil, *date_range)
|
72
|
+
possible_dims = ['date','site','zone','country','keyword','campaign','campaign_relationship','partner','agency']
|
73
|
+
possible_measures = ['paid_impressions','total_impressions','revenue','ecpm','rcpm','fill_rate']
|
74
|
+
|
75
|
+
args = parse_date date_range
|
76
|
+
args['currency'] = currency
|
77
|
+
args['dimensions'] = Array.new
|
78
|
+
args['measures'] = Array.new
|
79
|
+
|
80
|
+
dimensions.each { |dim| args['dimensions'] << dim if possible_dims.include? dim } if dimensions.is_a? Array
|
81
|
+
measures.each { |measure| args['measures'] << measure if possible_measures.include? measure } if measures.is_a? Array
|
82
|
+
|
83
|
+
path = "/seller/api/ips/v2/reports/performance/#{@id}/#{compose_arguments args}"
|
84
|
+
execute(path)
|
85
|
+
end
|
86
|
+
|
87
|
+
def execute(path)
|
88
|
+
super path
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubicon-api-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathan Hagen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple ruby api client for accessing the Rubicon Project's reporting
|
14
|
+
api
|
15
|
+
email: nathan@aggronn.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/rubicon-api-client.rb
|
21
|
+
homepage: https://github.com/nhagen/rubicon-api-client
|
22
|
+
licenses: []
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.0.0
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: A simple ruby api client for accessing the Rubicon Project's reporting api
|
44
|
+
test_files: []
|