adk2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 412d8e26fd1d32d8def4942f68b85ac6a1bec8c6
4
+ data.tar.gz: 4f288ad73a3e141e719fb7cab040f258705a3d02
5
+ SHA512:
6
+ metadata.gz: 4cd10471bc8ef3ad54eec6fa5a3b64a39589f3d9bcbbdb4024c287079f8e7db06d676eed2bc6adb0a1bb574b36e115de6127bd41327cacb102d7244e96f12454
7
+ data.tar.gz: ec604ec95ee78bc218dd5d0fb454cf99096fd6e5cba1bbfb7b2a194892c68f206d9a76b6745b674fde30f023df997f40603a503fd7ec836b0f1728e4183ee595
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .envrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in adk2.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Helge Rausch
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ # Adk2
2
+
3
+ [![Code Climate](https://codeclimate.com/github/ad2games/adk2/badges/gpa.svg)](https://codeclimate.com/github/ad2games/adk2)
4
+ [![Test Coverage](https://codeclimate.com/github/ad2games/adk2/badges/coverage.svg)](https://codeclimate.com/github/ad2games/adk2)
5
+ [![Circle CI](https://circleci.com/gh/ad2games/adk2.svg?style=svg)](https://circleci.com/gh/ad2games/adk2)
6
+
7
+ A ruby wrapper for accessing the ADK2 API.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'adk2'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install adk2
24
+
25
+ ## Usage
26
+
27
+ To initially generate an API token, you can use the `get_api_token` method:
28
+
29
+ ```ruby
30
+ api_token = Adk2::Client.new(network_name).get_api_token(username, password)
31
+ ```
32
+
33
+ To generate report, first create a new client instance:
34
+
35
+ ```ruby
36
+ client = Adk2::Client.new(network_name, api_token)
37
+ ```
38
+
39
+ Use the client to generate a report, e.g.:
40
+ ```ruby
41
+ client.report(
42
+ 'network',
43
+ 'networkanalyticsbydate',
44
+ '2015-02-01',
45
+ '2015-02-04'
46
+ )
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it (https://github.com/ad2games/adk2/fork)
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'adk2/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'adk2'
8
+ spec.version = Adk2::VERSION
9
+ spec.authors = ['ad2games GmbH']
10
+ spec.email = ['developers@ad2games.com']
11
+ spec.summary = 'API client for adk2'
12
+ spec.description = 'API client for adk2'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'rest-client'
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'vcr'
27
+ spec.add_development_dependency 'webmock'
28
+ spec.add_development_dependency 'codeclimate-test-reporter'
29
+ end
@@ -0,0 +1,2 @@
1
+ require 'adk2/client'
2
+ require 'adk2/version'
@@ -0,0 +1,44 @@
1
+ require 'rest-client'
2
+ require 'csv'
3
+ require 'json'
4
+
5
+ module Adk2
6
+ class Client
7
+ def initialize(network_name, api_token = '')
8
+ @api_base_url = "https://#{network_name}.adk2.com"
9
+ @api_token = api_token
10
+ end
11
+
12
+ def report(level, name, start_date, end_date)
13
+ response = RestClient.get(
14
+ "#{api_base_url}/denver/reports/#{level}/#{name}/#{start_date}-#{end_date}",
15
+ params: {
16
+ fmt: 'csv',
17
+ auth: @api_token
18
+ }
19
+ )
20
+
21
+ CSV.parse(response, headers: true).map(&:to_h)
22
+ end
23
+
24
+ def get_api_token(username, password)
25
+ response = RestClient.post(
26
+ api_base_url + '/auth',
27
+ {
28
+ 'email' => username,
29
+ 'password' => password
30
+ }.to_json
31
+ )
32
+
33
+ @api_token = RestClient.post(
34
+ api_base_url + '/intro/profile/apikey',
35
+ {},
36
+ cookies: response.cookies
37
+ )
38
+ end
39
+
40
+ private
41
+
42
+ attr_reader :api_base_url, :api_token
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module Adk2
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://adk2-network-name.adk2.com/denver/reports/network/networkanalyticsbydate/2015-02-01-2015-02-01?auth=adk2-api-token&fmt=csv
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
+ Cache-Control:
32
+ - private, max-age=0, must-revalidate
33
+ Content-Disposition:
34
+ - attachment; filename=networkanalyticsbydate_2015-02-01_2015-02-01.csv
35
+ Content-Encoding:
36
+ - gzip
37
+ Content-Type:
38
+ - text/csv
39
+ Date:
40
+ - Mon, 02 Feb 2015 09:43:17 GMT
41
+ Server:
42
+ - adk2
43
+ Content-Length:
44
+ - '253'
45
+ Connection:
46
+ - keep-alive
47
+ body:
48
+ encoding: ASCII-8BIT
49
+ string: !binary |-
50
+ H4sIAAAAAAAAA3WP64rCMBCF/wu+yRjmklufptQ67gZrW9JYX19NwV0XNjBk
51
+ vpMzc8ipKwplKt3QpuucdVnSNC4warlP+fKhnbthOHb9P+KsudexwJpOOrVr
52
+ 0vsC/ZD6y/OaxlXz5+Ksq443hfl2HNLyrflHydM5lbdR+/n6y7VhtWz9WjL0
53
+ r3qHtPn1p5rd/lWvXf5K437HSO6AfEACCYLsGISd9z6CDeKiBWLjGxcBwQk5
54
+ eD4IG3G4HWA0TaDoKxAZCZFsBTSI0QcW8WI9V3aemZCD5VBZ0OHLgOIq1zGy
55
+ vBFFIMOhsSDOUKCmkUjBUxP3uwfLAxwcsAEAAA==
56
+ http_version:
57
+ recorded_at: Mon, 02 Feb 2015 09:43:17 GMT
58
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,109 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://adk2-network-name.adk2.com/auth
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"email":"developers@adk2-network-name.com","password":"adk2-password"}'
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Length:
15
+ - '61'
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Access-Control-Allow-Credentials:
24
+ - 'true'
25
+ Access-Control-Allow-Headers:
26
+ - Authorization, origin, accept
27
+ Access-Control-Allow-Methods:
28
+ - GET, OPTIONS
29
+ Access-Control-Allow-Origin:
30
+ - "*"
31
+ Access-Control-Expose-Headers:
32
+ - X-Frames,X-Duration
33
+ Content-Encoding:
34
+ - gzip
35
+ Content-Type:
36
+ - application/json; charset=UTF-8
37
+ Date:
38
+ - Mon, 02 Feb 2015 09:22:48 GMT
39
+ Server:
40
+ - adk2
41
+ Set-Cookie:
42
+ - t1=cookie_monster
43
+ expires=Mon, 09 Feb 2015 09:22:48 GMT; httponly; Path=/
44
+ Content-Length:
45
+ - '151'
46
+ Connection:
47
+ - keep-alive
48
+ body:
49
+ encoding: ASCII-8BIT
50
+ string: !binary |-
51
+ H4sIAAAAAAAAA02NsQoCMRBEf+XYWiwsrRQrC8HCTuRYzXAGsknI3p2F+O9u
52
+ CB52+4aZt2/inJW23ZX2TnykVWfHIUVNARVOcJ7/+Dzdg9cnSmvOKKNXo5th
53
+ ZIGp6HjpRrDURrFZ0+f0Quknbcv80/TCkYcW8qJb0qqFsA/V6zAjpIyiO3ab
54
+ wb7p+pGEPl/PzniVxgAAAA==
55
+ http_version:
56
+ recorded_at: Mon, 02 Feb 2015 09:22:48 GMT
57
+ - request:
58
+ method: post
59
+ uri: https://adk2-network-name.adk2.com/intro/profile/apikey
60
+ body:
61
+ encoding: ASCII-8BIT
62
+ string: ''
63
+ headers:
64
+ Accept:
65
+ - "*/*; q=0.5, application/xml"
66
+ Accept-Encoding:
67
+ - gzip, deflate
68
+ Cookie:
69
+ - Path=%2F; t1=cookie_monster
70
+ Content-Length:
71
+ - '0'
72
+ Content-Type:
73
+ - application/x-www-form-urlencoded
74
+ User-Agent:
75
+ - Ruby
76
+ response:
77
+ status:
78
+ code: 200
79
+ message: OK
80
+ headers:
81
+ Access-Control-Allow-Credentials:
82
+ - 'true'
83
+ Access-Control-Allow-Headers:
84
+ - Authorization, origin, accept
85
+ Access-Control-Allow-Methods:
86
+ - GET, OPTIONS
87
+ Access-Control-Allow-Origin:
88
+ - "*"
89
+ Access-Control-Expose-Headers:
90
+ - X-Frames,X-Duration
91
+ Content-Encoding:
92
+ - gzip
93
+ Content-Type:
94
+ - text/plain
95
+ Date:
96
+ - Mon, 02 Feb 2015 09:22:48 GMT
97
+ Server:
98
+ - adk2
99
+ Content-Length:
100
+ - '52'
101
+ Connection:
102
+ - keep-alive
103
+ body:
104
+ encoding: ASCII-8BIT
105
+ string: !binary |-
106
+ H4sIAO5Cz1QAA0ssyNQtyc9OzQMAIVlIPQkAAAA=
107
+ http_version:
108
+ recorded_at: Mon, 02 Feb 2015 09:22:49 GMT
109
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Getting an API token', :vcr do
4
+ it 'updates the API token' do
5
+ expect(Adk2::Client.new(ENV['ADK2_NETWORK_NAME'])
6
+ .get_api_token(ENV['ADK2_USERNAME'], ENV['ADK2_PASSWORD'])).to eq('api-token')
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ describe 'Getting a report', :vcr do
5
+ subject { Adk2::Client.new(ENV['ADK2_NETWORK_NAME'], ENV['ADK2_API_TOKEN']) }
6
+
7
+ it 'gets the report' do
8
+ report = subject.report(
9
+ 'network',
10
+ 'networkanalyticsbydate',
11
+ '2015-02-01',
12
+ '2015-02-01'
13
+ )
14
+
15
+ expect(report).to be_a(Array)
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
3
+
4
+ require 'vcr'
5
+ require './lib/adk2'
6
+
7
+ ENV['ADK2_NETWORK_NAME'] ||= 'adk2-network-name'
8
+ ENV['ADK2_USERNAME'] ||= 'adk2-username'
9
+ ENV['ADK2_PASSWORD'] ||= 'adk2-password'
10
+ ENV['ADK2_API_TOKEN'] ||= 'adk2-api-key'
11
+
12
+ RSpec.configure do |config|
13
+ config.expect_with :rspec do |expectations|
14
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
15
+ end
16
+
17
+ config.mock_with :rspec do |mocks|
18
+ mocks.verify_partial_doubles = true
19
+ end
20
+
21
+ config.order = :random
22
+ config.warnings = true
23
+ end
24
+
25
+ VCR.configure do |c|
26
+ c.configure_rspec_metadata!
27
+
28
+ c.cassette_library_dir = 'spec/fixtures/vcr'
29
+ c.hook_into :webmock
30
+
31
+ c.filter_sensitive_data('adk2-network-name') { ENV['ADK2_NETWORK_NAME'] }
32
+ c.filter_sensitive_data('adk2-api-token') { ENV['ADK2_API_TOKEN'] }
33
+ c.filter_sensitive_data('adk2-username') { ENV['ADK2_USERNAME'] }
34
+ c.filter_sensitive_data('adk2-password') { ENV['ADK2_PASSWORD'] }
35
+
36
+ c.ignore_hosts 'codeclimate.com'
37
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adk2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ad2games GmbH
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: codeclimate-test-reporter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: API client for adk2
126
+ email:
127
+ - developers@ad2games.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".ruby-version"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - adk2.gemspec
140
+ - lib/adk2.rb
141
+ - lib/adk2/client.rb
142
+ - lib/adk2/version.rb
143
+ - spec/fixtures/vcr/Getting_a_report/gets_the_report.yml
144
+ - spec/fixtures/vcr/Getting_an_API_token/updates_the_API_token.yml
145
+ - spec/integration/get_api_token_spec.rb
146
+ - spec/integration/report_spec.rb
147
+ - spec/spec_helper.rb
148
+ homepage: ''
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.4.5
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: API client for adk2
172
+ test_files:
173
+ - spec/fixtures/vcr/Getting_a_report/gets_the_report.yml
174
+ - spec/fixtures/vcr/Getting_an_API_token/updates_the_API_token.yml
175
+ - spec/integration/get_api_token_spec.rb
176
+ - spec/integration/report_spec.rb
177
+ - spec/spec_helper.rb