metrika 0.1.2 → 0.1.3
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.
- data/.rspec +2 -1
- data/VERSION +1 -1
- data/lib/metrika/errors.rb +2 -2
- data/lib/metrika/helpers/request.rb +16 -2
- data/metrika.gemspec +5 -2
- data/spec/cases/metrika/counters_spec.rb +70 -3
- data/spec/fixtures/cassettes/counter_237991.yml +49 -0
- data/spec/fixtures/cassettes/counter_237992.yml +71 -0
- data/spec/fixtures/cassettes/counters.yml +2 -2
- data/spec/fixtures/cassettes/non_existent_counter.yml +70 -0
- data/spec/helper.rb +0 -1
- metadata +6 -3
data/.rspec
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
--
|
1
|
+
--format nested
|
2
|
+
--color
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/metrika/errors.rb
CHANGED
@@ -12,7 +12,7 @@ module Metrika
|
|
12
12
|
class UnauthorizedError < MetrikaError; end
|
13
13
|
class GeneralError < MetrikaError; end
|
14
14
|
class AccessDeniedError < MetrikaError; end
|
15
|
-
class NoTokenError <
|
16
|
-
class NotFoundError <
|
15
|
+
class NoTokenError < MetrikaError; end
|
16
|
+
class NotFoundError < MetrikaError; end
|
17
17
|
end
|
18
18
|
end
|
@@ -11,9 +11,12 @@ module Metrika
|
|
11
11
|
protected
|
12
12
|
|
13
13
|
def get(path, params = {}, options = {})
|
14
|
-
|
14
|
+
begin
|
15
|
+
response = self.token.get(path, DEFAULT_OPTIONS.merge(:params => params).merge(options))
|
16
|
+
rescue OAuth2::Error => e
|
17
|
+
self.process_oauth2_errors(e.response.status, e.message, path, params)
|
18
|
+
end
|
15
19
|
|
16
|
-
# self.raise_errors(response)
|
17
20
|
Yajl::Parser.parse(response.body)
|
18
21
|
end
|
19
22
|
|
@@ -40,6 +43,17 @@ module Metrika
|
|
40
43
|
# self.raise_errors(response)
|
41
44
|
Yajl::Parser.parse(response.body)
|
42
45
|
end
|
46
|
+
|
47
|
+
def process_oauth2_errors(status, message, path = nil, params = {})
|
48
|
+
case status
|
49
|
+
when 404
|
50
|
+
raise Metrika::Errors::NotFoundError.new(:message => message, :path => path, :params => params)
|
51
|
+
when 403
|
52
|
+
raise Metrika::Errors::AccessDeniedError.new(:message => message, :path => path, :params => params)
|
53
|
+
else
|
54
|
+
raise Metrika::Errors::MetrikaError.new(:message => message, :path => path, :params => params)
|
55
|
+
end
|
56
|
+
end
|
43
57
|
end
|
44
58
|
end
|
45
59
|
end
|
data/metrika.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "metrika"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Igor Alexandrov"]
|
12
|
-
s.date = "2012-10-
|
12
|
+
s.date = "2012-10-28"
|
13
13
|
s.email = "igor.alexandrov@gmail.com"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -38,7 +38,10 @@ Gem::Specification.new do |s|
|
|
38
38
|
"spec/cases/metrika/authorization_spec.rb",
|
39
39
|
"spec/cases/metrika/counters_spec.rb",
|
40
40
|
"spec/cases/metrika_spec.rb",
|
41
|
+
"spec/fixtures/cassettes/counter_237991.yml",
|
42
|
+
"spec/fixtures/cassettes/counter_237992.yml",
|
41
43
|
"spec/fixtures/cassettes/counters.yml",
|
44
|
+
"spec/fixtures/cassettes/non_existent_counter.yml",
|
42
45
|
"spec/helper.rb"
|
43
46
|
]
|
44
47
|
s.homepage = "http://github.com/igor-alexandrov/metrika"
|
@@ -1,7 +1,23 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
|
3
|
+
RSpec::Matchers.define :be_a_counter_hash do |expected|
|
4
|
+
match do |actual|
|
5
|
+
actual.should be_instance_of(Hash)
|
6
|
+
|
7
|
+
actual.should have_key('code_options')
|
8
|
+
actual.should have_key('code_status')
|
9
|
+
actual.should have_key('name')
|
10
|
+
actual.should have_key('permission')
|
11
|
+
actual.should have_key('monitoring')
|
12
|
+
actual.should have_key('site')
|
13
|
+
actual.should have_key('id')
|
14
|
+
actual.should have_key('type')
|
15
|
+
actual.should have_key('owner_login')
|
16
|
+
actual.should have_key('code')
|
17
|
+
end
|
18
|
+
end
|
4
19
|
|
20
|
+
describe Metrika do
|
5
21
|
before(:all) do
|
6
22
|
Metrika.configure do |config|
|
7
23
|
config.application_id = APPLICATION_ID
|
@@ -13,12 +29,63 @@ describe Metrika do
|
|
13
29
|
end
|
14
30
|
|
15
31
|
context '#get_counters' do
|
16
|
-
it 'should
|
32
|
+
it 'should be' do
|
33
|
+
VCR.use_cassette("counters") do
|
34
|
+
lambda {
|
35
|
+
counters = @client.get_counters
|
36
|
+
counters.should_not be_nil
|
37
|
+
}.should_not raise_error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should return array of counter hashes' do
|
17
42
|
VCR.use_cassette('counters') do
|
18
43
|
counters = @client.get_counters
|
19
44
|
counters.should be_instance_of(Array)
|
20
|
-
counters.size.should > 0
|
45
|
+
counters.size.should > 0
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context '#get_counter' do
|
51
|
+
before(:all) do
|
52
|
+
VCR.use_cassette('counters') do
|
53
|
+
@counter_id = @client.get_counters[0]['id']
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should be' do
|
58
|
+
VCR.use_cassette("counter_#{@counter_id}") do
|
59
|
+
lambda {
|
60
|
+
counter = @client.get_counter(@counter_id)
|
61
|
+
counter.should_not be_nil
|
62
|
+
}.should_not raise_error
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should return a counter hash' do
|
67
|
+
VCR.use_cassette("counter_#{@counter_id}") do
|
68
|
+
counter = @client.get_counter(@counter_id)
|
69
|
+
counter.should be_a_counter_hash
|
21
70
|
end
|
22
71
|
end
|
72
|
+
|
73
|
+
it 'should raise NotAuthorizedError when trying to get counter that you do not have ability to get' do
|
74
|
+
another_counter_id = 237992
|
75
|
+
VCR.use_cassette("counter_#{another_counter_id}") do
|
76
|
+
lambda {
|
77
|
+
counter = @client.get_counter(another_counter_id)
|
78
|
+
}.should raise_error(Metrika::Errors::AccessDeniedError)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should raise NotFoundError when trying to get counter that does not exist' do
|
83
|
+
VCR.use_cassette('non_existent_counter') do
|
84
|
+
lambda {
|
85
|
+
counter = @client.get_counter('non_existent_counter')
|
86
|
+
}.should raise_error(Metrika::Errors::NotFoundError)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
23
90
|
end
|
24
91
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api-metrika.yandex.ru/counter/237991
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/x-yametrika+json
|
12
|
+
Content-Type:
|
13
|
+
- application/x-yametrika+json
|
14
|
+
Authorization:
|
15
|
+
- Bearer 926b254ca2f24869999a3d404a01f616
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
User-Agent:
|
19
|
+
- Ruby
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Pragma:
|
26
|
+
- no-cache
|
27
|
+
Cache-Control:
|
28
|
+
- no-cache, no-store, max-age=0, must-revalidate
|
29
|
+
Expires:
|
30
|
+
- Thu, 01 Jan 1970 00:00:00 GMT
|
31
|
+
Date:
|
32
|
+
- Sun, 28 Oct 2012 10:06:07 GMT
|
33
|
+
Server:
|
34
|
+
- Apache/2.2
|
35
|
+
Content-Type:
|
36
|
+
- application/x-yametrika+json
|
37
|
+
Transfer-Encoding:
|
38
|
+
- chunked
|
39
|
+
body:
|
40
|
+
encoding: US-ASCII
|
41
|
+
string: ! '{"counter":{"code_options":{"denial":0,"clickmap":0,"async":0,"informer":{"color_arrow":1,"color_start":"FFFFFFFF","color_text":0,"size":3,"allowed":0,"color_end":"EFEFEFFF","indicator":"pageviews","type":"ext","enabled":0},"track_hash":0,"ut":0,"params":0,"external_links":0,"webvisor_load_player":"on-your-behalf"},"code_status":"CS_OK","name":null,"permission":"own","monitoring":{"enable_monitoring":0,"enable_sms":0,"sms_time":"9-20;9-20;9-20;9-20;9-20;9-20;9-20","emails":["igor.alexandrov@gmail.com"],"sms_allowed":1},"site":"www.requestbilling.com","id":237991,"type":"simple","owner_login":"igor-alexandrov","code":"<!--
|
42
|
+
Yandex.Metrika counter -->\n<script src=\"\/\/mc.yandex.ru\/metrika\/watch.js\"
|
43
|
+
type=\"text\/javascript\"><\/script>\n<script type=\"text\/javascript\">\ntry
|
44
|
+
{ var yaCounter237991 = new Ya.Metrika({id:237991});}\ncatch(e) { }\n<\/script>\n<noscript><div><img
|
45
|
+
src=\"\/\/mc.yandex.ru\/watch\/237991\" style=\"position:absolute; left:-9999px;\"
|
46
|
+
alt=\"\" \/><\/div><\/noscript>\n<!-- \/Yandex.Metrika counter -->"}}'
|
47
|
+
http_version:
|
48
|
+
recorded_at: Sun, 28 Oct 2012 10:06:08 GMT
|
49
|
+
recorded_with: VCR 2.2.5
|
@@ -0,0 +1,71 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api-metrika.yandex.ru/counter/237992
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/x-yametrika+json
|
12
|
+
Content-Type:
|
13
|
+
- application/x-yametrika+json
|
14
|
+
Authorization:
|
15
|
+
- Bearer 926b254ca2f24869999a3d404a01f616
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
User-Agent:
|
19
|
+
- Ruby
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 403
|
23
|
+
message: !binary |-
|
24
|
+
Rm9yYmlkZGVu
|
25
|
+
headers:
|
26
|
+
!binary "UHJhZ21h":
|
27
|
+
- !binary |-
|
28
|
+
bm8tY2FjaGU=
|
29
|
+
!binary "Q2FjaGUtQ29udHJvbA==":
|
30
|
+
- !binary |-
|
31
|
+
bm8tY2FjaGUsIG5vLXN0b3JlLCBtYXgtYWdlPTAsIG11c3QtcmV2YWxpZGF0
|
32
|
+
ZQ==
|
33
|
+
!binary "RXhwaXJlcw==":
|
34
|
+
- !binary |-
|
35
|
+
VGh1LCAwMSBKYW4gMTk3MCAwMDowMDowMCBHTVQ=
|
36
|
+
!binary "RGF0ZQ==":
|
37
|
+
- !binary |-
|
38
|
+
U3VuLCAyOCBPY3QgMjAxMiAxMDowNjowOCBHTVQ=
|
39
|
+
!binary "U2VydmVy":
|
40
|
+
- !binary |-
|
41
|
+
QXBhY2hlLzIuMg==
|
42
|
+
!binary "TGFzdC1Nb2RpZmllZA==":
|
43
|
+
- !binary |-
|
44
|
+
V2VkLCAxNCBNYXIgMjAxMiAxMTo0NjoyMSBHTVQ=
|
45
|
+
!binary "RXRhZw==":
|
46
|
+
- !binary |-
|
47
|
+
ImExMTRlLTQ5LTRiYjMyODYzMTlkNDAi
|
48
|
+
!binary "QWNjZXB0LVJhbmdlcw==":
|
49
|
+
- !binary |-
|
50
|
+
Ynl0ZXM=
|
51
|
+
!binary "VmFyeQ==":
|
52
|
+
- !binary |-
|
53
|
+
QWNjZXB0LUVuY29kaW5n
|
54
|
+
!binary "Q29udGVudC1FbmNvZGluZw==":
|
55
|
+
- !binary |-
|
56
|
+
Z3ppcA==
|
57
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
58
|
+
- !binary |-
|
59
|
+
OTI=
|
60
|
+
!binary "Q29udGVudC1UeXBl":
|
61
|
+
- !binary |-
|
62
|
+
dGV4dC9odG1sOyBjaGFyc2V0PXV0Zi04
|
63
|
+
body:
|
64
|
+
encoding: ASCII-8BIT
|
65
|
+
string: !binary |-
|
66
|
+
H4sIAAAAAAAAA7PxMLQzMTBWcMsvSspMSUnNs9EHinBF5pcqpOTnqZcoZCSW
|
67
|
+
pSoUpBblZhYXZ+bnKZTkKyQmJ6cWFyuUZGQWKxSlFueXFiWncgEAVB5PQkkA
|
68
|
+
AAA=
|
69
|
+
http_version:
|
70
|
+
recorded_at: Sun, 28 Oct 2012 10:06:08 GMT
|
71
|
+
recorded_with: VCR 2.2.5
|
@@ -35,7 +35,7 @@ http_interactions:
|
|
35
35
|
VGh1LCAwMSBKYW4gMTk3MCAwMDowMDowMCBHTVQ=
|
36
36
|
!binary "RGF0ZQ==":
|
37
37
|
- !binary |-
|
38
|
-
|
38
|
+
U3VuLCAyOCBPY3QgMjAxMiAxMDowNjowNiBHTVQ=
|
39
39
|
!binary "U2VydmVy":
|
40
40
|
- !binary |-
|
41
41
|
QXBhY2hlLzIuMg==
|
@@ -78,5 +78,5 @@ http_interactions:
|
|
78
78
|
cGUiOiJzaW1wbGUiLCJpZCI6MTUwNjgxMSwib3duZXJfbG9naW4iOiJpZ29y
|
79
79
|
LWFsZXhhbmRyb3YifV19
|
80
80
|
http_version:
|
81
|
-
recorded_at:
|
81
|
+
recorded_at: Sun, 28 Oct 2012 10:06:07 GMT
|
82
82
|
recorded_with: VCR 2.2.5
|
@@ -0,0 +1,70 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://api-metrika.yandex.ru/counter/non_existent_counter
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/x-yametrika+json
|
12
|
+
Content-Type:
|
13
|
+
- application/x-yametrika+json
|
14
|
+
Authorization:
|
15
|
+
- Bearer 926b254ca2f24869999a3d404a01f616
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
User-Agent:
|
19
|
+
- Ruby
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 404
|
23
|
+
message: !binary |-
|
24
|
+
Tm90IEZvdW5k
|
25
|
+
headers:
|
26
|
+
!binary "UHJhZ21h":
|
27
|
+
- !binary |-
|
28
|
+
bm8tY2FjaGU=
|
29
|
+
!binary "Q2FjaGUtQ29udHJvbA==":
|
30
|
+
- !binary |-
|
31
|
+
bm8tY2FjaGUsIG5vLXN0b3JlLCBtYXgtYWdlPTAsIG11c3QtcmV2YWxpZGF0
|
32
|
+
ZQ==
|
33
|
+
!binary "RXhwaXJlcw==":
|
34
|
+
- !binary |-
|
35
|
+
VGh1LCAwMSBKYW4gMTk3MCAwMDowMDowMCBHTVQ=
|
36
|
+
!binary "RGF0ZQ==":
|
37
|
+
- !binary |-
|
38
|
+
U3VuLCAyOCBPY3QgMjAxMiAxMDowNjowOCBHTVQ=
|
39
|
+
!binary "U2VydmVy":
|
40
|
+
- !binary |-
|
41
|
+
QXBhY2hlLzIuMg==
|
42
|
+
!binary "TGFzdC1Nb2RpZmllZA==":
|
43
|
+
- !binary |-
|
44
|
+
V2VkLCAxNCBNYXIgMjAxMiAxMTo0NjoyMSBHTVQ=
|
45
|
+
!binary "RXRhZw==":
|
46
|
+
- !binary |-
|
47
|
+
ImExMTRiLTM4LTRiYjMyODYzMTlkNDAi
|
48
|
+
!binary "QWNjZXB0LVJhbmdlcw==":
|
49
|
+
- !binary |-
|
50
|
+
Ynl0ZXM=
|
51
|
+
!binary "VmFyeQ==":
|
52
|
+
- !binary |-
|
53
|
+
QWNjZXB0LUVuY29kaW5n
|
54
|
+
!binary "Q29udGVudC1FbmNvZGluZw==":
|
55
|
+
- !binary |-
|
56
|
+
Z3ppcA==
|
57
|
+
!binary "Q29udGVudC1MZW5ndGg=":
|
58
|
+
- !binary |-
|
59
|
+
NzA=
|
60
|
+
!binary "Q29udGVudC1UeXBl":
|
61
|
+
- !binary |-
|
62
|
+
dGV4dC9odG1sOyBjaGFyc2V0PXV0Zi04
|
63
|
+
body:
|
64
|
+
encoding: ASCII-8BIT
|
65
|
+
string: !binary |-
|
66
|
+
H4sIAAAAAAAAA7PxMLQzMTBR8MsvUXDLL81LsdEHinCFZKQqFKUWlqYWl6Sm
|
67
|
+
AFnF+aVFyakKeUBVaSBVXABtZ1XKOAAAAA==
|
68
|
+
http_version:
|
69
|
+
recorded_at: Sun, 28 Oct 2012 10:06:08 GMT
|
70
|
+
recorded_with: VCR 2.2.5
|
data/spec/helper.rb
CHANGED
@@ -20,7 +20,6 @@ end
|
|
20
20
|
APPLICATION_ID = '663576cbd55948a4ae45424fb508ef97'
|
21
21
|
APPLICATION_PASSWORD = 'fc2f76dc877e41a4a6cbe78d73faff85'
|
22
22
|
|
23
|
-
# ACCESS_TOKEN = '926b254ca2f24869999a3d404a01f616'
|
24
23
|
token_file = File.expand_path('../.access_token', __FILE__)
|
25
24
|
if File.exists?(token_file)
|
26
25
|
ACCESS_TOKEN = File.read(token_file).strip
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metrika
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|
@@ -137,7 +137,10 @@ files:
|
|
137
137
|
- spec/cases/metrika/authorization_spec.rb
|
138
138
|
- spec/cases/metrika/counters_spec.rb
|
139
139
|
- spec/cases/metrika_spec.rb
|
140
|
+
- spec/fixtures/cassettes/counter_237991.yml
|
141
|
+
- spec/fixtures/cassettes/counter_237992.yml
|
140
142
|
- spec/fixtures/cassettes/counters.yml
|
143
|
+
- spec/fixtures/cassettes/non_existent_counter.yml
|
141
144
|
- spec/helper.rb
|
142
145
|
homepage: http://github.com/igor-alexandrov/metrika
|
143
146
|
licenses:
|
@@ -154,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
157
|
version: '0'
|
155
158
|
segments:
|
156
159
|
- 0
|
157
|
-
hash:
|
160
|
+
hash: 3580690976981475761
|
158
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
162
|
none: false
|
160
163
|
requirements:
|