openrtb-client 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.travis.yml +21 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +1 -0
- data/Rakefile +11 -0
- data/lib/openrtb.rb +6 -0
- data/lib/openrtb/client.rb +114 -0
- data/lib/openrtb/error.rb +5 -0
- data/lib/openrtb/null_object.rb +14 -0
- data/lib/openrtb/request.rb +8 -0
- data/lib/openrtb/response.rb +8 -0
- data/lib/openrtb/version.rb +3 -0
- data/openrtb-client.gemspec +33 -0
- data/test/fixtures/response.json +25 -0
- data/test/helper.rb +3 -0
- data/test/test_client.rb +58 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a014bcbe57f7cf7df9bd4902e94ec8ca279200e7
|
4
|
+
data.tar.gz: fbf9529ddaaabcda7a986c39ce76db2d90c3103a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7cc2a4a1ad904fc6e77d7b1d00dd025e477aaee3facc1ca53401e81fdb0c149c7a7cd80f8369e0b20e2c626fac91606a5848372ae7b54093310e862a5f21d70
|
7
|
+
data.tar.gz: 9e76be854c51f896d9bc69714174ba9765b1f5292a5be1833e3c2d01f0591fd4e0987bd6539cc527f01469b2bc690b51d21f46faaa6e87e655ef06aa75ae13b6
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- JRUBY_OPTS="$JRUBY_OPTS --debug"
|
4
|
+
language: ruby
|
5
|
+
rvm:
|
6
|
+
- 1.9.3
|
7
|
+
- 2.0.0
|
8
|
+
- 2.1.1
|
9
|
+
- ruby-head
|
10
|
+
- jruby-head
|
11
|
+
- jruby-19mode
|
12
|
+
- rbx-19mode
|
13
|
+
matrix:
|
14
|
+
allow_failures:
|
15
|
+
- rvm: ruby-head
|
16
|
+
- rvm: jruby-head
|
17
|
+
- rvm: rbx-19mode
|
18
|
+
fast_finish: true
|
19
|
+
notifications:
|
20
|
+
email:
|
21
|
+
- dev@realmediadigital.com
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Realmedia Latin America
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# OpenRTB Ruby Client
|
data/Rakefile
ADDED
data/lib/openrtb.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'typhoeus'
|
4
|
+
|
5
|
+
Typhoeus::Config.memoize = false
|
6
|
+
Typhoeus::Config.verbose = false
|
7
|
+
|
8
|
+
module OpenRTB
|
9
|
+
class Client
|
10
|
+
attr_accessor :proxy
|
11
|
+
attr_writer :logger, :max_concurrency, :user_agent, :version
|
12
|
+
|
13
|
+
class Queue
|
14
|
+
include NullObject::Conversions
|
15
|
+
|
16
|
+
def initialize(client, hydra)
|
17
|
+
@client = client
|
18
|
+
@hydra = hydra
|
19
|
+
end
|
20
|
+
|
21
|
+
def responses
|
22
|
+
@responses ||= []
|
23
|
+
end
|
24
|
+
|
25
|
+
def post(endpoint, body = {})
|
26
|
+
req = request(endpoint, :post, OpenRTB::Request.new(body))
|
27
|
+
req.on_complete { |res| responses << res }
|
28
|
+
|
29
|
+
@hydra.queue req
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def request(endpoint, method, body)
|
35
|
+
uri = Addressable::URI.parse(Just(endpoint))
|
36
|
+
opt = {body: MultiJson.dump(body), method: method}
|
37
|
+
opt.merge!(userpwd: uri.userinfo) if uri.userinfo
|
38
|
+
|
39
|
+
Typhoeus::Request.new(uri.omit(:userinfo).to_s, options(opt))
|
40
|
+
end
|
41
|
+
|
42
|
+
def options(hash = {})
|
43
|
+
hash[:proxy] = @client.proxy
|
44
|
+
hash[:headers] ||= {}
|
45
|
+
hash[:headers]['Content-Type'] = 'application/json'
|
46
|
+
hash[:headers]['User-Agent'] = @client.user_agent
|
47
|
+
hash[:headers]['x-openrtb-version'] = @client.version
|
48
|
+
hash[:timeout] = 1
|
49
|
+
hash[:connecttimeout] = 1
|
50
|
+
hash[:followlocation] = false
|
51
|
+
hash[:accept_encoding] = 'gzip'
|
52
|
+
hash[:ssl_verifypeer] = false
|
53
|
+
hash[:ssl_verifyhost] = 0
|
54
|
+
hash
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def initialize
|
59
|
+
yield(self) if block_given?
|
60
|
+
end
|
61
|
+
|
62
|
+
def logger
|
63
|
+
@logger ||= OpenRTB::NullObject.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def max_concurrency
|
67
|
+
@max_concurrency ||= 2
|
68
|
+
end
|
69
|
+
|
70
|
+
def user_agent
|
71
|
+
@user_agent ||= "OpenRTB Ruby Client #{OpenRTB::VERSION}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def version
|
75
|
+
@version ||= '2.1'
|
76
|
+
end
|
77
|
+
|
78
|
+
def execute(&block)
|
79
|
+
hydra = Typhoeus::Hydra.new(max_concurrency: max_concurrency)
|
80
|
+
queue = Queue.new(self, hydra)
|
81
|
+
block.call(queue)
|
82
|
+
hydra.run
|
83
|
+
|
84
|
+
handle_responses(queue.responses)
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def handle_responses(responses)
|
90
|
+
result = []
|
91
|
+
responses.each do |res|
|
92
|
+
begin
|
93
|
+
logger.debug({
|
94
|
+
effective_url: res.effective_url,
|
95
|
+
primary_ip: res.primary_ip,
|
96
|
+
response_code: res.response_code,
|
97
|
+
response_headers: res.response_headers,
|
98
|
+
namelookup_time: res.namelookup_time,
|
99
|
+
connect_time: res.connect_time,
|
100
|
+
app_connect_time: res.app_connect_time,
|
101
|
+
pretransfer_time: res.pretransfer_time,
|
102
|
+
start_transfer_time: res.start_transfer_time,
|
103
|
+
total_time: res.total_time,
|
104
|
+
body: res.body})
|
105
|
+
|
106
|
+
result.push OpenRTB::Response.new(MultiJson.load(res.body)) if res.success?
|
107
|
+
rescue MultiJson::ParseError => e
|
108
|
+
logger.error(e.cause)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
result
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'openrtb/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.name = 'openrtb-client'
|
8
|
+
s.version = OpenRTB::VERSION
|
9
|
+
s.summary = %Q{OpenRTB Ruby Client}
|
10
|
+
s.description = %Q{OpenRTB Ruby Client}
|
11
|
+
s.author = 'Realmedia Latin America'
|
12
|
+
s.email = 'dev@realmediadigital.com'
|
13
|
+
s.homepage = 'http://github.com/realmedia/openrtb-ruby-client'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.required_ruby_version = '>= 1.9.3'
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split('\n')
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ['lib']
|
22
|
+
|
23
|
+
s.add_dependency 'addressable', '~> 2.3.6'
|
24
|
+
s.add_dependency 'hashie', '~> 3.2.0'
|
25
|
+
s.add_dependency 'multi_json', '~> 1.10.1'
|
26
|
+
s.add_dependency 'naught', '~> 1.0.0'
|
27
|
+
s.add_dependency 'nesty', '~> 1.0.2'
|
28
|
+
s.add_dependency 'typhoeus', '~> 0.6.9'
|
29
|
+
|
30
|
+
s.add_development_dependency 'rake', '~> 10.3'
|
31
|
+
s.add_development_dependency 'minitest', '~> 5.2'
|
32
|
+
s.add_development_dependency 'webmock', '~> 1.18'
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"id": "BID-4-ZIMP-4b309eae-504a-4252-a8a8-4c8ceee9791a",
|
3
|
+
"seatbid": [
|
4
|
+
{
|
5
|
+
"bid": [
|
6
|
+
{
|
7
|
+
"id": "32a69c6ba388f110487f9d1e63f77b22d86e916b",
|
8
|
+
"impid": "32a69c6ba388f110487f9d1e63f77b22d86e916b",
|
9
|
+
"price": 0.065445,
|
10
|
+
"adid": "529833ce55314b19e8796116",
|
11
|
+
"nurl": "http://ads.com/win/529833ce55314b19e8796116?won=${AUCTION_PRICE}",
|
12
|
+
"adm": "<iframe src=\"http://ads.com/render/529833ce55314b19e8796116\" width=\"300\" height=\"250\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" topmargin=\"0\" leftmargin=\"0\"></iframe>",
|
13
|
+
"adomain": [
|
14
|
+
"ads.com"
|
15
|
+
],
|
16
|
+
"cid": "529833ce55314b19e8796116",
|
17
|
+
"crid": "529833ce55314b19e8796116_1385706446",
|
18
|
+
"attr": []
|
19
|
+
}
|
20
|
+
],
|
21
|
+
"seat": "772"
|
22
|
+
}
|
23
|
+
],
|
24
|
+
"cur": "USD"
|
25
|
+
}
|
data/test/helper.rb
ADDED
data/test/test_client.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'webmock'
|
3
|
+
WebMock.disable_net_connect!
|
4
|
+
|
5
|
+
describe OpenRTB::Client do
|
6
|
+
include WebMock::API
|
7
|
+
|
8
|
+
let(:endpoint) { 'http://api.example.org/exchange.json' }
|
9
|
+
let(:request) { {
|
10
|
+
id: 1
|
11
|
+
} }
|
12
|
+
let(:headers) { {
|
13
|
+
'User-Agent' => @client.user_agent,
|
14
|
+
'Content-Type' => 'application/json',
|
15
|
+
'X-Openrtb-Version' => @client.version
|
16
|
+
} }
|
17
|
+
|
18
|
+
before do
|
19
|
+
@client = OpenRTB::Client.new
|
20
|
+
end
|
21
|
+
|
22
|
+
after do
|
23
|
+
WebMock.reset!
|
24
|
+
end
|
25
|
+
|
26
|
+
def fixture(file)
|
27
|
+
File.new(File.join(File.expand_path('../fixtures', __FILE__), file))
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#execute' do
|
31
|
+
it 'encodes the body and makes the request with the correct headers' do
|
32
|
+
stub_request(:post, endpoint).to_return(status: 200, body: fixture('response.json'))
|
33
|
+
|
34
|
+
responses = @client.execute do |q|
|
35
|
+
q.post(endpoint, request)
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_requested(:post, endpoint, times: 1) do |req|
|
39
|
+
assert_equal MultiJson.dump(request), req.body
|
40
|
+
assert_equal headers, req.headers
|
41
|
+
end
|
42
|
+
|
43
|
+
assert_equal responses.size, 1
|
44
|
+
responses.each { |res| assert_instance_of OpenRTB::Response, res }
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'makes multiple requests' do
|
48
|
+
stub_request(:post, endpoint).to_return(status: 200, body: fixture('response.json'))
|
49
|
+
|
50
|
+
responses = @client.execute do |q|
|
51
|
+
q.post(endpoint, request)
|
52
|
+
q.post(endpoint, request)
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_requested(:post, endpoint, times: 2)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openrtb-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Realmedia Latin America
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.3.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.3.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hashie
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: multi_json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.10.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.10.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: naught
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nesty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.0.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.0.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: typhoeus
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.6.9
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.6.9
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.3'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.3'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '5.2'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '5.2'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.18'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '1.18'
|
139
|
+
description: OpenRTB Ruby Client
|
140
|
+
email: dev@realmediadigital.com
|
141
|
+
executables: []
|
142
|
+
extensions: []
|
143
|
+
extra_rdoc_files: []
|
144
|
+
files:
|
145
|
+
- ".gitignore"
|
146
|
+
- ".travis.yml"
|
147
|
+
- Gemfile
|
148
|
+
- LICENSE
|
149
|
+
- README.md
|
150
|
+
- Rakefile
|
151
|
+
- lib/openrtb.rb
|
152
|
+
- lib/openrtb/client.rb
|
153
|
+
- lib/openrtb/error.rb
|
154
|
+
- lib/openrtb/null_object.rb
|
155
|
+
- lib/openrtb/request.rb
|
156
|
+
- lib/openrtb/response.rb
|
157
|
+
- lib/openrtb/version.rb
|
158
|
+
- openrtb-client.gemspec
|
159
|
+
- test/fixtures/response.json
|
160
|
+
- test/helper.rb
|
161
|
+
- test/test_client.rb
|
162
|
+
homepage: http://github.com/realmedia/openrtb-ruby-client
|
163
|
+
licenses:
|
164
|
+
- MIT
|
165
|
+
metadata: {}
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: 1.9.3
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
requirements: []
|
181
|
+
rubyforge_project:
|
182
|
+
rubygems_version: 2.2.2
|
183
|
+
signing_key:
|
184
|
+
specification_version: 4
|
185
|
+
summary: OpenRTB Ruby Client
|
186
|
+
test_files: []
|