admob-api 0.0.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/.gitignore +18 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +89 -0
- data/Rakefile +10 -0
- data/admob-api.gemspec +28 -0
- data/lib/admob-api.rb +10 -0
- data/lib/admob-api/client.rb +73 -0
- data/lib/admob-api/date_range.rb +67 -0
- data/lib/admob-api/errors.rb +5 -0
- data/lib/admob-api/site.rb +5 -0
- data/lib/admob-api/stats.rb +5 -0
- data/lib/admob-api/validator.rb +31 -0
- data/lib/admob-api/version.rb +3 -0
- data/spec/client_spec.rb +65 -0
- data/spec/date_range_spec.rb +63 -0
- data/spec/fixtures/login.json +1 -0
- data/spec/fixtures/search_site.json +1 -0
- data/spec/fixtures/site_stats.json +1 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/validator_spec.rb +34 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1ba29a57b38931e00fea1e20711e5add69a47dda
|
4
|
+
data.tar.gz: 1f9b5f1332290d99a5cca3bb19ea93a7cfce95af
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4821b3dd404551c122d7ee2fdebebad7bab2a4c37841d3187ed0ff0ebffd9bb26b4a97bf712ec776fee56d73935991617ae3117fc2911d935c6a4ba704012876
|
7
|
+
data.tar.gz: 70ef51da4cbd82c9ef46cb1376e3c1ad1fb446a8859dd199193ed51803ad75a10d1ea7133b1eb9caed81cbceaf4ef6d28c8a66c7e6a1c655fab4ee27699f28fe
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 mako2x
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
AdMob API [](https://travis-ci.org/mako2x/admob-api)
|
2
|
+
===
|
3
|
+
|
4
|
+
A Ruby interface to the Admob API
|
5
|
+
|
6
|
+
Installation
|
7
|
+
---
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'admob-api'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install admob-api
|
20
|
+
|
21
|
+
Usage
|
22
|
+
---
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'admob-api'
|
26
|
+
|
27
|
+
# Authentication
|
28
|
+
admob = AdMobApi.new do |c|
|
29
|
+
c.client_key = 'yourclientkey'
|
30
|
+
c.email = 'foobar@mail.com'
|
31
|
+
c.password = 'yourpassword'
|
32
|
+
end
|
33
|
+
|
34
|
+
# Site
|
35
|
+
sites = admob.sites
|
36
|
+
p sites.first.id
|
37
|
+
p sites.first.name
|
38
|
+
p sites.first.description
|
39
|
+
p sites.first.url
|
40
|
+
|
41
|
+
# Stats
|
42
|
+
stats = admob.stats(sites.first.id)
|
43
|
+
stats = admob.stats(sites.first.id, :yesterday)
|
44
|
+
stats = admob.stats(sites.map(&:id), :last_7days)
|
45
|
+
stats = admob.stats(sites.map(&:id), :last_30days)
|
46
|
+
stats = admob.stats(sites.map(&:id), :previous_month)
|
47
|
+
stats = admob.stats(sites.map(&:id), :previous_quarter)
|
48
|
+
stats = admob.stats(sites.map(&:id), :quarter_to_date)
|
49
|
+
stats = admob.stats(sites.map(&:id), Date.new(2013, 1, 1)..Date.new(2013, 3, 31), {
|
50
|
+
:order_by => :impressions,
|
51
|
+
:order => :asc
|
52
|
+
})
|
53
|
+
p stats.clicks
|
54
|
+
p stats.requests
|
55
|
+
p stats.revenue
|
56
|
+
p stats.impressions
|
57
|
+
p stats.ctr
|
58
|
+
p stats.ecpm
|
59
|
+
p stats.fill_rate
|
60
|
+
p stats.date
|
61
|
+
p stats.cpc_impressions
|
62
|
+
p stats.cpc_revenue
|
63
|
+
p stats.cpm_impressions
|
64
|
+
p stats.cpm_revenue
|
65
|
+
p stats.exchange_downloads
|
66
|
+
p stats.exchange_impressions
|
67
|
+
p stats.housead_clicks
|
68
|
+
p stats.housead_ctr
|
69
|
+
p stats.housead_fill_rate
|
70
|
+
p stats.housead_impressions
|
71
|
+
p stats.housead_requests
|
72
|
+
p stats.interstitial_impressions
|
73
|
+
p stats.interstitial_requests
|
74
|
+
p stats.overall_fill_rate
|
75
|
+
p stats.overall_requests
|
76
|
+
|
77
|
+
# Logout
|
78
|
+
admob.logout
|
79
|
+
|
80
|
+
```
|
81
|
+
|
82
|
+
Contributing
|
83
|
+
---
|
84
|
+
|
85
|
+
1. Fork it
|
86
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
87
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
88
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
89
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/admob-api.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'admob-api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'admob-api'
|
8
|
+
spec.version = AdMobApi::VERSION
|
9
|
+
spec.authors = ['mako2x']
|
10
|
+
spec.email = ['arekara3nen@gmail.com']
|
11
|
+
spec.description = %q{A Ruby interface to the Admob API}
|
12
|
+
spec.summary = %q{A Ruby interface to the Admob API}
|
13
|
+
spec.homepage = 'https://github.com/mako2x/admob-api'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'webmock'
|
25
|
+
spec.add_dependency 'httpclient'
|
26
|
+
spec.add_dependency 'hashie'
|
27
|
+
spec.add_dependency 'quarter_time'
|
28
|
+
end
|
data/lib/admob-api.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'httpclient'
|
2
|
+
require 'json'
|
3
|
+
require 'admob-api/site'
|
4
|
+
require 'admob-api/stats'
|
5
|
+
require 'admob-api/validator'
|
6
|
+
require 'admob-api/date_range'
|
7
|
+
|
8
|
+
class AdMobApi
|
9
|
+
class Client
|
10
|
+
attr_writer :client_key, :email, :password
|
11
|
+
|
12
|
+
private
|
13
|
+
def get(path, params = {})
|
14
|
+
request(:get, path, params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(path, params = {})
|
18
|
+
request(:post, path, params)
|
19
|
+
end
|
20
|
+
|
21
|
+
include AdMobApi::Validator
|
22
|
+
def request(method, path, params = {})
|
23
|
+
params[:client_key] = @client_key
|
24
|
+
params[:token] = @token
|
25
|
+
res = @agent.request(method, AdMobApi::URL + path, params)
|
26
|
+
content = JSON.parse(res.content)
|
27
|
+
validate(content)
|
28
|
+
content['data']
|
29
|
+
end
|
30
|
+
|
31
|
+
public
|
32
|
+
def initialize(&block)
|
33
|
+
block.call(self)
|
34
|
+
|
35
|
+
@agent = HTTPClient.new
|
36
|
+
res = post('/v2/auth/login', {
|
37
|
+
:email => @email,
|
38
|
+
:password => @password
|
39
|
+
})
|
40
|
+
@token = res['token']
|
41
|
+
end
|
42
|
+
|
43
|
+
def logout
|
44
|
+
post('/v2/auth/logout')
|
45
|
+
@client_key, @email, @password, @token = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def sites(include_deleted = false)
|
49
|
+
params = include_deleted ? {:include_deleted => 1} : {}
|
50
|
+
res = get('/v2/site/search', params)
|
51
|
+
res.map {|s| AdMobApi::Site.new(s) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def stats(site_id, date_range = :today, opt = {})
|
55
|
+
if date_range.is_a?(Symbol)
|
56
|
+
date_range = AdMobApi::DateRange.send(date_range)
|
57
|
+
end
|
58
|
+
site_id_key = site_id.is_a?(Array) ? 'site_id[]' : :site_id
|
59
|
+
params = {
|
60
|
+
site_id_key => site_id,
|
61
|
+
:start_date => date_range.begin,
|
62
|
+
:end_date => date_range.end
|
63
|
+
}
|
64
|
+
params[:object_dimention] = opt[:object_dimention] unless opt[:object_dimention].nil?
|
65
|
+
params[:time_dimention] = opt[:time_dimention] unless opt[:time_dimention].nil?
|
66
|
+
unless opt[:order_by].nil?
|
67
|
+
params["order_by[#{opt[:order_by]}]"] = opt[:order] || :desc
|
68
|
+
end
|
69
|
+
res = get('/v2/site/stats', params)
|
70
|
+
AdMobApi::Stats.new(res.first)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'quarter_time'
|
2
|
+
|
3
|
+
class AdMobApi
|
4
|
+
class DateRange < Range
|
5
|
+
class << self
|
6
|
+
def today
|
7
|
+
today = Date.today
|
8
|
+
DateRange.new(today, today)
|
9
|
+
end
|
10
|
+
|
11
|
+
def yesterday
|
12
|
+
today = Date.today
|
13
|
+
DateRange.new(today - 1, today - 1)
|
14
|
+
end
|
15
|
+
|
16
|
+
def last_days(days)
|
17
|
+
today = Date.today
|
18
|
+
DateRange.new(today - days, today)
|
19
|
+
end
|
20
|
+
|
21
|
+
def previous_month
|
22
|
+
one_month_ago = Date.today << 1
|
23
|
+
DateRange.new(begining_of_the_month(one_month_ago), end_of_the_month(one_month_ago))
|
24
|
+
end
|
25
|
+
|
26
|
+
def previous_quarter
|
27
|
+
today = Date.today
|
28
|
+
quarter = Quarter.new(today.year, today.quarter).previous
|
29
|
+
DateRange.new(quarter.start_date, quarter.end_date)
|
30
|
+
end
|
31
|
+
|
32
|
+
def month_to_date
|
33
|
+
today = Date.today
|
34
|
+
DateRange.new(begining_of_the_month(today), today)
|
35
|
+
end
|
36
|
+
|
37
|
+
def quarter_to_date
|
38
|
+
today = Date.today
|
39
|
+
quarter = Quarter.new(today.year, today.quarter)
|
40
|
+
DateRange.new(quarter.start_date, today)
|
41
|
+
end
|
42
|
+
|
43
|
+
def year_to_date
|
44
|
+
today = Date.today
|
45
|
+
DateRange.new(Date.new(today.year, 1, 1), today)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def begining_of_the_month(date)
|
50
|
+
Date.new(date.year, date.month, 1)
|
51
|
+
end
|
52
|
+
|
53
|
+
def end_of_the_month(date)
|
54
|
+
one_month_later = date >> 1
|
55
|
+
begining_of_the_month(one_month_later) - 1
|
56
|
+
end
|
57
|
+
|
58
|
+
def method_missing(method_name, *args, &block)
|
59
|
+
if method_name =~ /last_(\d+)days/
|
60
|
+
send(:last_days, $1.to_i)
|
61
|
+
else
|
62
|
+
super
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'admob-api/errors'
|
2
|
+
|
3
|
+
class AdMobApi
|
4
|
+
module Validator
|
5
|
+
AUTH_ERROR_MSG = [
|
6
|
+
'Invalid email or password.',
|
7
|
+
/^client_key has invalid value /,
|
8
|
+
/^(client_key|email|password) is a required parameter./
|
9
|
+
]
|
10
|
+
|
11
|
+
UNAUTHORIZED_ERROR_MSG = [
|
12
|
+
/^token has invalid value /,
|
13
|
+
'token is a required parameter.'
|
14
|
+
]
|
15
|
+
|
16
|
+
def validate(res)
|
17
|
+
res['warnings'].each { |w| puts "Warning: #{w['msg']}" }
|
18
|
+
|
19
|
+
res['errors'].each do |e|
|
20
|
+
case e['msg']
|
21
|
+
when *AUTH_ERROR_MSG
|
22
|
+
raise AdMobApi::AuthenticationError, e['msg']
|
23
|
+
when *UNAUTHORIZED_ERROR_MSG
|
24
|
+
raise AdMobApi::UnauthorizedError, 'Authentication required'
|
25
|
+
else
|
26
|
+
raise AdMobApi::ClientError, e['msg']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe AdMobApi::Client do
|
4
|
+
let(:client_key) { '123456789abcdefghijklmnopqrstuvw' }
|
5
|
+
let(:admob) do
|
6
|
+
email = 'admob@gmail.com'
|
7
|
+
password = 'password'
|
8
|
+
|
9
|
+
stub_post('/v2/auth/login')
|
10
|
+
.with(:query => {
|
11
|
+
:client_key => client_key,
|
12
|
+
:email => email,
|
13
|
+
:password => password,
|
14
|
+
:token => nil
|
15
|
+
})
|
16
|
+
.to_return(:body => fixture('login.json'))
|
17
|
+
|
18
|
+
AdMobApi.new do |c|
|
19
|
+
c.client_key = client_key
|
20
|
+
c.email = email
|
21
|
+
c.password = password
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#sites' do
|
26
|
+
it 'returns array of site' do
|
27
|
+
stub_get('/v2/site/search')
|
28
|
+
.with(:query => {
|
29
|
+
:client_key => client_key,
|
30
|
+
:token => admob.instance_variable_get(:@token),
|
31
|
+
})
|
32
|
+
.to_return(:body => fixture('search_site.json'))
|
33
|
+
|
34
|
+
site = admob.sites.find { |s| s.name == 'foo' }
|
35
|
+
expect(site.id).to eq 'a11111111111111'
|
36
|
+
expect(site.name).to eq 'foo'
|
37
|
+
expect(site.url).to eq 'market://details?id=com.foo.bar'
|
38
|
+
expect(site.description).to eq 'foobar'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#sites' do
|
43
|
+
it 'returns site stats' do
|
44
|
+
id = 'a11111111111111'
|
45
|
+
start_date = Date.new(2013, 6, 1)
|
46
|
+
end_date = Date.new(2013, 6, 6)
|
47
|
+
stub_get('/v2/site/stats')
|
48
|
+
.with(:query => {
|
49
|
+
:client_key => client_key,
|
50
|
+
:token => admob.instance_variable_get(:@token),
|
51
|
+
:site_id => id,
|
52
|
+
:start_date => start_date,
|
53
|
+
:end_date => end_date
|
54
|
+
})
|
55
|
+
.to_return(:body => fixture('site_stats.json'))
|
56
|
+
|
57
|
+
stats = admob.stats(id, start_date..end_date)
|
58
|
+
expect(stats.clicks).to be 89312
|
59
|
+
expect(stats.revenue).to be 4483.1018
|
60
|
+
expect(stats.ecpm).to be 1.186
|
61
|
+
expect(stats.impressions).to be 3779956
|
62
|
+
expect(stats.date).to eq "#{start_date}/#{end_date}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe AdMobApi::DateRange do
|
4
|
+
before do
|
5
|
+
allow(Date).to receive(:today).and_return(Date.new(2013, 7, 16))
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.today' do
|
9
|
+
it 'returns range of today' do
|
10
|
+
expected = Date.new(2013, 7, 16)..Date.new(2013, 7, 16)
|
11
|
+
expect(AdMobApi::DateRange.today).to eq expected
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.yesterday' do
|
16
|
+
it 'returns range of yesterday' do
|
17
|
+
expected = Date.new(2013, 7, 15)..Date.new(2013, 7, 15)
|
18
|
+
expect(AdMobApi::DateRange.yesterday).to eq expected
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.last_7days' do
|
23
|
+
it 'returns range of last 7 days' do
|
24
|
+
expected = Date.new(2013, 7, 9)..Date.new(2013, 7, 16)
|
25
|
+
expect(AdMobApi::DateRange.last_7days).to eq expected
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.previous_month' do
|
30
|
+
it 'returns range of previous month' do
|
31
|
+
expected = Date.new(2013, 6, 1)..Date.new(2013, 6, 30)
|
32
|
+
expect(AdMobApi::DateRange.previous_month).to eq expected
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '.previous_quarter' do
|
37
|
+
it 'returns range of previous quarter' do
|
38
|
+
expected = Date.new(2013, 4, 1)..Date.new(2013, 6, 30)
|
39
|
+
expect(AdMobApi::DateRange.previous_quarter).to eq expected
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '.month_to_date' do
|
44
|
+
it 'returns range of month to date' do
|
45
|
+
expected = Date.new(2013, 7, 1)..Date.new(2013, 7, 16)
|
46
|
+
expect(AdMobApi::DateRange.month_to_date).to eq expected
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '.quarter_to_date' do
|
51
|
+
it 'returns range of quarter to date' do
|
52
|
+
expected = Date.new(2013, 7, 1)..Date.new(2013, 7, 16)
|
53
|
+
expect(AdMobApi::DateRange.quarter_to_date).to eq expected
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '.year_to_date' do
|
58
|
+
it 'returns range of year to date' do
|
59
|
+
expected = Date.new(2013, 1, 1)..Date.new(2013, 7, 16)
|
60
|
+
expect(AdMobApi::DateRange.year_to_date).to eq expected
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errors":[],"warnings":[],"data":{"token":"123456789abcdefghijklmnopqrstuvw"},"page":{"current":1,"total":1}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errors":[],"warnings":[],"data":[{"id":"a11111111111111","name":"foo","url":"market:\/\/details?id=com.foo.bar","description":"foobar"},{"id":"a22222222222222","name":"hoge","url":"market:\/\/details?id=com.hoge.piyo","description":"hogepiyofuga"}],"page":{"current":1,"total":1}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"errors":[],"warnings":[],"data":[{"requests":3780351,"overall_requests":3780351,"housead_requests":0,"interstitial_requests":0,"impressions":3779956,"cpc_impressions":3776445,"cpm_impressions":3511,"exchange_impressions":0,"housead_impressions":0,"interstitial_impressions":0,"fill_rate":0.9999,"housead_fill_rate":0,"overall_fill_rate":0.9999,"clicks":89312,"housead_clicks":0,"ctr":0.0236,"housead_ctr":0,"ecpm":1.186,"revenue":4483.1018,"cpc_revenue":4481.9826,"cpm_revenue":1.1192,"exchange_downloads":0,"date":"2013-06-01\/2013-06-06"}],"page":{"current":1,"total":1}}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
|
3
|
+
require 'admob-api'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
|
7
|
+
def stub_get(path)
|
8
|
+
WebMock.stub_request(:get, AdMobApi::URL + path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def stub_post(path)
|
12
|
+
WebMock.stub_request(:post, AdMobApi::URL + path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def fixture(file)
|
16
|
+
File.new("#{File.dirname(__FILE__)}/fixtures/#{file}")
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe AdMobApi::Validator do
|
4
|
+
include AdMobApi::Validator
|
5
|
+
|
6
|
+
describe '#validate' do
|
7
|
+
subject { ->{ validate(response) } }
|
8
|
+
let(:response) { { 'errors' => errors, 'warnings' => [] } }
|
9
|
+
|
10
|
+
context 'when response contains error' do
|
11
|
+
let(:errors) { [ {'msg' => msg} ] }
|
12
|
+
|
13
|
+
context 'when password is invalid' do
|
14
|
+
let(:msg) { 'Invalid email or password.' }
|
15
|
+
it { should raise_error AdMobApi::AuthenticationError }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when client key is invalid' do
|
19
|
+
let(:msg) { 'client_key has invalid value 123456789abc.' }
|
20
|
+
it { should raise_error AdMobApi::AuthenticationError }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when unauthorized' do
|
24
|
+
let(:msg) { 'token is a required parameter.' }
|
25
|
+
it { should raise_error AdMobApi::UnauthorizedError }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when response doesn't contain error" do
|
30
|
+
let(:errors) { [] }
|
31
|
+
it { should_not raise_error }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: admob-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mako2x
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
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: httpclient
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
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: hashie
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
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: quarter_time
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: A Ruby interface to the Admob API
|
112
|
+
email:
|
113
|
+
- arekara3nen@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .travis.yml
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- admob-api.gemspec
|
125
|
+
- lib/admob-api.rb
|
126
|
+
- lib/admob-api/client.rb
|
127
|
+
- lib/admob-api/date_range.rb
|
128
|
+
- lib/admob-api/errors.rb
|
129
|
+
- lib/admob-api/site.rb
|
130
|
+
- lib/admob-api/stats.rb
|
131
|
+
- lib/admob-api/validator.rb
|
132
|
+
- lib/admob-api/version.rb
|
133
|
+
- spec/client_spec.rb
|
134
|
+
- spec/date_range_spec.rb
|
135
|
+
- spec/fixtures/login.json
|
136
|
+
- spec/fixtures/search_site.json
|
137
|
+
- spec/fixtures/site_stats.json
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
- spec/validator_spec.rb
|
140
|
+
homepage: https://github.com/mako2x/admob-api
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.0.3
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: A Ruby interface to the Admob API
|
164
|
+
test_files:
|
165
|
+
- spec/client_spec.rb
|
166
|
+
- spec/date_range_spec.rb
|
167
|
+
- spec/fixtures/login.json
|
168
|
+
- spec/fixtures/search_site.json
|
169
|
+
- spec/fixtures/site_stats.json
|
170
|
+
- spec/spec_helper.rb
|
171
|
+
- spec/validator_spec.rb
|