adk2 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -5
- data/adk2.gemspec +1 -0
- data/lib/adk2/client.rb +29 -14
- data/lib/adk2/version.rb +1 -1
- data/spec/fixtures/vcr/Getting_a_report/gets_the_report.yml +13 -11
- data/spec/fixtures/vcr/Getting_an_entity/gets_a_single_entity.yml +55 -0
- data/spec/integration/entity_spec.rb +12 -0
- data/spec/integration/get_api_token_spec.rb +9 -2
- data/spec/integration/report_spec.rb +28 -5
- data/spec/spec_helper.rb +12 -2
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f3424b26aa32a125d4c8a5ebf87578fb21c729d
|
4
|
+
data.tar.gz: 286456f416e8a6341987a82b27b00712e526ec20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f63613b167fc19c9132ac66d7007cfd0d893fead07779ea774963e0fdff783a615fef3fc1e4c644bf48dc794bf0bcb38e5714393e91ed837457ca5c7a26fe97f
|
7
|
+
data.tar.gz: 7e582b3199f39c85e435968552386b38aa0ccd13b5a19919bd3825dab3048ffd0043783c923961541ecfa558ebd1bc8bde8edfb16a8190060975d31f98528acf
|
data/README.md
CHANGED
@@ -24,19 +24,24 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
To
|
27
|
+
To instantiate the client:
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
|
30
|
+
client = Adk2::Client.new(network_name, username: 'foo@example.com', password: '123456')
|
31
31
|
```
|
32
32
|
|
33
|
-
|
33
|
+
Alternatively, you can use an API token:
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
client = Adk2::Client.new(network_name, api_token)
|
36
|
+
client = Adk2::Client.new(network_name, api_token: 'tokentokentoken')
|
37
37
|
```
|
38
38
|
|
39
|
-
|
39
|
+
In case the API token expires (TODO: when does this happen?), with the
|
40
|
+
first version the client automatically will fetch a new one. With the
|
41
|
+
second version it won't.
|
42
|
+
|
43
|
+
Use the client to generate a report:
|
44
|
+
|
40
45
|
```ruby
|
41
46
|
client.report(
|
42
47
|
'network',
|
data/adk2.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_dependency 'rest-client'
|
22
|
+
spec.add_dependency 'retryable'
|
22
23
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
25
|
spec.add_development_dependency 'pry'
|
data/lib/adk2/client.rb
CHANGED
@@ -1,32 +1,36 @@
|
|
1
|
-
require 'rest-client'
|
2
1
|
require 'csv'
|
3
2
|
require 'json'
|
3
|
+
require 'rest-client'
|
4
|
+
require 'retryable'
|
4
5
|
|
5
6
|
module Adk2
|
6
7
|
class Client
|
7
|
-
def initialize(network_name,
|
8
|
+
def initialize(network_name, opts = {})
|
8
9
|
@api_base_url = "https://#{network_name}.adk2.com"
|
9
|
-
@
|
10
|
+
@username = opts[:username]
|
11
|
+
@password = opts[:password]
|
12
|
+
@api_token = opts[:api_token]
|
10
13
|
end
|
11
14
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
params: {
|
16
|
-
fmt: 'csv',
|
17
|
-
auth: @api_token
|
18
|
-
}
|
19
|
-
)
|
15
|
+
def entities(type, params = {})
|
16
|
+
JSON.parse(http_get(type, { rows: 1000 }.merge(params)), symbolize_names: true)[:rows]
|
17
|
+
end
|
20
18
|
|
19
|
+
def entity(type, id)
|
20
|
+
JSON.parse(http_get("#{type}/#{id}"), symbolize_names: true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def report(level, name, start_date, end_date)
|
24
|
+
response = http_get("reports/#{level}/#{name}/#{start_date}-#{end_date}", fmt: 'csv')
|
21
25
|
CSV.parse(response, headers: true).map(&:to_h)
|
22
26
|
end
|
23
27
|
|
24
|
-
def get_api_token
|
28
|
+
def get_api_token
|
25
29
|
response = RestClient.post(
|
26
30
|
api_base_url + '/auth',
|
27
31
|
{
|
28
|
-
'email' => username,
|
29
|
-
'password' =>
|
32
|
+
'email' => @username,
|
33
|
+
'password' => @username
|
30
34
|
}.to_json
|
31
35
|
)
|
32
36
|
|
@@ -40,5 +44,16 @@ module Adk2
|
|
40
44
|
private
|
41
45
|
|
42
46
|
attr_reader :api_base_url, :api_token
|
47
|
+
|
48
|
+
def http_get(path, params = {})
|
49
|
+
Retryable.retryable(tries: 1, on: RestClient::Forbidden) do |_, exception|
|
50
|
+
get_api_token if exception
|
51
|
+
|
52
|
+
RestClient.get(
|
53
|
+
"#{api_base_url}/denver/#{path}",
|
54
|
+
params: { fmt: 'json', auth: @api_token }.merge(params)
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
43
58
|
end
|
44
59
|
end
|
data/lib/adk2/version.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://adk2-network-name.adk2.com/denver/reports/network/networkanalyticsbydate/
|
5
|
+
uri: https://adk2-network-name.adk2.com/denver/reports/network/networkanalyticsbydate/2014-12-01-2014-12-01?auth=adk2-api-token&fmt=csv
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
@@ -31,28 +31,30 @@ http_interactions:
|
|
31
31
|
Cache-Control:
|
32
32
|
- private, max-age=0, must-revalidate
|
33
33
|
Content-Disposition:
|
34
|
-
- attachment; filename=
|
34
|
+
- attachment; filename=networkanalyticsbydate_2014-12-01_2014-12-01.csv
|
35
35
|
Content-Encoding:
|
36
36
|
- gzip
|
37
37
|
Content-Type:
|
38
38
|
- text/csv
|
39
39
|
Date:
|
40
|
-
-
|
40
|
+
- Tue, 03 Feb 2015 16:39:44 GMT
|
41
41
|
Server:
|
42
42
|
- adk2
|
43
|
+
X-Last-Updated:
|
44
|
+
- '2015-02-03 16:08:32'
|
43
45
|
Content-Length:
|
44
|
-
- '
|
46
|
+
- '245'
|
45
47
|
Connection:
|
46
48
|
- keep-alive
|
47
49
|
body:
|
48
50
|
encoding: ASCII-8BIT
|
49
51
|
string: !binary |-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
H4sIAAAAAAAAA3WPa4rDMAyE/xd6EzVIlh/JaULqqrumiR0cN71+8yjd7cIa
|
53
|
+
bM18jCR86YpASaXr2zCMWaYppDhBlPJI+fbBrl3fnzv/Dxwle4kF5nCR1M5B
|
54
|
+
HhP4PvjbUlKcJX8OzjJLvAuM93Mfpm/JPySnayjvoPhx+JXa7RbZ9Vwy+PW+
|
55
|
+
l7R5/dO2u/1Lhy5/hXg8KCR9InVCAiJ2ennRGGBqQFU1agsIGhRgpU2D21k0
|
56
|
+
kyGndk2aa1XvGjWyMdRYtLT2oHIOm9pqu/DVk7LaMJM2zq3+1cZmS5OzYF6U
|
57
|
+
qWI26Kwyyinm4+EJY/Nz9qIBAAA=
|
56
58
|
http_version:
|
57
|
-
recorded_at:
|
59
|
+
recorded_at: Tue, 03 Feb 2015 16:39:44 GMT
|
58
60
|
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://adk2-network-name.adk2.com/denver/publishers/1?auth=adk2-api-token&fmt=json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Access-Control-Allow-Credentials:
|
22
|
+
- 'true'
|
23
|
+
Access-Control-Allow-Headers:
|
24
|
+
- Authorization, origin, accept
|
25
|
+
Access-Control-Allow-Methods:
|
26
|
+
- GET, OPTIONS
|
27
|
+
Access-Control-Allow-Origin:
|
28
|
+
- "*"
|
29
|
+
Access-Control-Expose-Headers:
|
30
|
+
- X-Frames,X-Duration
|
31
|
+
Content-Encoding:
|
32
|
+
- gzip
|
33
|
+
Content-Type:
|
34
|
+
- application/json; charset=UTF-8
|
35
|
+
Date:
|
36
|
+
- Wed, 04 Feb 2015 13:06:04 GMT
|
37
|
+
Server:
|
38
|
+
- adk2
|
39
|
+
Content-Length:
|
40
|
+
- '610'
|
41
|
+
Connection:
|
42
|
+
- keep-alive
|
43
|
+
body:
|
44
|
+
encoding: ASCII-8BIT
|
45
|
+
string: !binary |-
|
46
|
+
H4sIAJ030lQAA3VRy2rDMBC89yuCjqUJtkNSyCmpz20NLb2UENbW2hboYSS5jWv879UqIekhBWNZ
|
47
|
+
szM7u+ORVeCxMXZgm1maZKuHGXMefO/Cne26zpov5Cyg4Bx6QkemQEODNn73Du1BgvMHDQpJVIIl
|
48
|
+
fizUwv6p1MawaQq1ymJw5YRlSbqaJ9k8Wc7S9SY8y4TUrgVLmnSREN9oD1V0/xxZbPpy7tkJ3ZCA
|
49
|
+
Rrhg5oRZI+P91bcYZ+Lg2tKAJWdvewyQcIUVCuL+NUhHGCoQkoR4BNVJ3J7PRWUUm/YUhpTmG3mQ
|
50
|
+
VuQfxmJ5sSOLvMjpKIqP0+2ZEV8ZLmpxa+PscZOsY75VZXp92SE3qusbaUqQ7dChVdiARk/Ma/ys
|
51
|
+
lNBu6bU4Dj/sj9HTcLMMPReext1f/8I/VIsu5OjwPbjH4FmDGsPCVOxM12t+CvU+bugDjfq8edCc
|
52
|
+
EiaWNWFyL6J+nKa7X5LfkxBuAgAA
|
53
|
+
http_version:
|
54
|
+
recorded_at: Wed, 04 Feb 2015 13:06:04 GMT
|
55
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Getting an entity', :vcr do
|
4
|
+
subject do
|
5
|
+
Adk2::Client.new(ENV['ADK2_NETWORK_NAME'], api_token: ENV['ADK2_API_TOKEN'])
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'gets a single entity' do
|
9
|
+
publisher = subject.entity('publishers', 1)
|
10
|
+
expect(publisher[:accountName]).to eq('Compuglobalhypermeganet')
|
11
|
+
end
|
12
|
+
end
|
@@ -1,8 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Getting an API token', :vcr do
|
4
|
+
subject do
|
5
|
+
Adk2::Client.new(
|
6
|
+
ENV['ADK2_NETWORK_NAME'],
|
7
|
+
username: ENV['ADK2_USERNAME'],
|
8
|
+
password: ENV['ADK2_PASSWORD']
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
4
12
|
it 'updates the API token' do
|
5
|
-
expect(
|
6
|
-
.get_api_token(ENV['ADK2_USERNAME'], ENV['ADK2_PASSWORD'])).to eq('api-token')
|
13
|
+
expect(subject.get_api_token).to eq('api-token')
|
7
14
|
end
|
8
15
|
end
|
@@ -1,17 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'pry'
|
3
2
|
|
4
3
|
describe 'Getting a report', :vcr do
|
5
|
-
subject
|
4
|
+
subject do
|
5
|
+
Adk2::Client.new(ENV['ADK2_NETWORK_NAME'], api_token: ENV['ADK2_API_TOKEN'])
|
6
|
+
end
|
6
7
|
|
7
8
|
it 'gets the report' do
|
8
9
|
report = subject.report(
|
9
10
|
'network',
|
10
11
|
'networkanalyticsbydate',
|
11
|
-
'
|
12
|
-
'
|
12
|
+
'2014-12-01',
|
13
|
+
'2014-12-01'
|
13
14
|
)
|
14
15
|
|
15
|
-
expect(report).to
|
16
|
+
expect(report).to eq([
|
17
|
+
{
|
18
|
+
"date" => "2014-12-01",
|
19
|
+
"total_impressions" => "11374",
|
20
|
+
"network_impressions" => "11055",
|
21
|
+
"fallback_impressions" => "319",
|
22
|
+
"fallback_percent" => "2.8046",
|
23
|
+
"video_views" => "0",
|
24
|
+
"clicks" => "4",
|
25
|
+
"conversions" => "2",
|
26
|
+
"network_revenue" => "0.459000000",
|
27
|
+
"publisher_revenue" => "0.315172000",
|
28
|
+
"profit" => "0.143828000",
|
29
|
+
"network_ecpm" => "0.0403551960612",
|
30
|
+
"publisher_ecpm" => "0.0277098646035",
|
31
|
+
"profit_ecpm" => "0.0126453314577",
|
32
|
+
"vtr" => "0.0000",
|
33
|
+
"ctr" => "0.0352",
|
34
|
+
"conversion_rate" => "0.0176",
|
35
|
+
"click_conversion_rate" => "50.0000",
|
36
|
+
"margin" => "31.3350762527233"
|
37
|
+
}
|
38
|
+
])
|
16
39
|
end
|
17
40
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
if ENV['CODECLIMATE_REPO_TOKEN']
|
2
|
+
require 'codeclimate-test-reporter'
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
end
|
3
5
|
|
6
|
+
require 'pry'
|
4
7
|
require 'vcr'
|
5
8
|
require './lib/adk2'
|
6
9
|
|
@@ -18,6 +21,13 @@ RSpec.configure do |config|
|
|
18
21
|
mocks.verify_partial_doubles = true
|
19
22
|
end
|
20
23
|
|
24
|
+
config.before(:example) do
|
25
|
+
# The cert is invalid on my machine. So, not verifying it for now. - @tsujigiri
|
26
|
+
allow(RestClient::Request).to receive(:new).and_wrap_original do |method, opts|
|
27
|
+
method.call(opts.merge(verify_ssl: false))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
21
31
|
config.order = :random
|
22
32
|
config.warnings = true
|
23
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adk2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ad2games GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: retryable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,6 +156,8 @@ files:
|
|
142
156
|
- lib/adk2/version.rb
|
143
157
|
- spec/fixtures/vcr/Getting_a_report/gets_the_report.yml
|
144
158
|
- spec/fixtures/vcr/Getting_an_API_token/updates_the_API_token.yml
|
159
|
+
- spec/fixtures/vcr/Getting_an_entity/gets_a_single_entity.yml
|
160
|
+
- spec/integration/entity_spec.rb
|
145
161
|
- spec/integration/get_api_token_spec.rb
|
146
162
|
- spec/integration/report_spec.rb
|
147
163
|
- spec/spec_helper.rb
|
@@ -172,6 +188,8 @@ summary: API client for adk2
|
|
172
188
|
test_files:
|
173
189
|
- spec/fixtures/vcr/Getting_a_report/gets_the_report.yml
|
174
190
|
- spec/fixtures/vcr/Getting_an_API_token/updates_the_API_token.yml
|
191
|
+
- spec/fixtures/vcr/Getting_an_entity/gets_a_single_entity.yml
|
192
|
+
- spec/integration/entity_spec.rb
|
175
193
|
- spec/integration/get_api_token_spec.rb
|
176
194
|
- spec/integration/report_spec.rb
|
177
195
|
- spec/spec_helper.rb
|