serp_metrics 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE +22 -0
  5. data/README.md +25 -0
  6. data/Rakefile +1 -0
  7. data/lib/serp_metrics.rb +25 -0
  8. data/lib/serp_metrics/client.rb +34 -0
  9. data/lib/serp_metrics/command_sets/account.rb +13 -0
  10. data/lib/serp_metrics/command_sets/base.rb +47 -0
  11. data/lib/serp_metrics/command_sets/engines.rb +9 -0
  12. data/lib/serp_metrics/command_sets/flux.rb +13 -0
  13. data/lib/serp_metrics/command_sets/keywords.rb +41 -0
  14. data/lib/serp_metrics/command_sets/priorities.rb +23 -0
  15. data/lib/serp_metrics/commands.rb +23 -0
  16. data/lib/serp_metrics/response.rb +5 -0
  17. data/lib/serp_metrics/version.rb +3 -0
  18. data/serp_metrics.gemspec +22 -0
  19. data/spec/api_credentials.yml.sample +2 -0
  20. data/spec/cassettes/serp_metrics__command_sets__account/credit_fetches_credit_information.yml +46 -0
  21. data/spec/cassettes/serp_metrics__command_sets__account/time_fetches_time.yml +38 -0
  22. data/spec/cassettes/serp_metrics__command_sets__engines/codes_fetches_search_engine_codes.yml +221 -0
  23. data/spec/cassettes/serp_metrics__command_sets__flux/flux_fetches_flux_trend.yml +46 -0
  24. data/spec/cassettes/serp_metrics__command_sets__keywords/add_adds_keyword.yml +163 -0
  25. data/spec/cassettes/serp_metrics__command_sets__keywords/all_retrieves_keywords.yml +206 -0
  26. data/spec/cassettes/serp_metrics__command_sets__keywords/check_retrieves_checks.yml +206 -0
  27. data/spec/cassettes/serp_metrics__command_sets__keywords/remove_removes_keyword.yml +200 -0
  28. data/spec/cassettes/serp_metrics__command_sets__keywords/serp_retrieves_serp_for_check.yml +165 -0
  29. data/spec/cassettes/serp_metrics__command_sets__priorities/add_with_location_adds_priority.yml +40 -0
  30. data/spec/cassettes/serp_metrics__command_sets__priorities/add_without_location_adds_priority.yml +40 -0
  31. data/spec/cassettes/serp_metrics__command_sets__priorities/get_checks_priority.yml +79 -0
  32. data/spec/lib/serp_metrics/client_spec.rb +27 -0
  33. data/spec/lib/serp_metrics/command_sets/account_spec.rb +27 -0
  34. data/spec/lib/serp_metrics/command_sets/engines_spec.rb +22 -0
  35. data/spec/lib/serp_metrics/command_sets/flux_spec.rb +23 -0
  36. data/spec/lib/serp_metrics/command_sets/keywords_spec.rb +90 -0
  37. data/spec/lib/serp_metrics/command_sets/priorities_spec.rb +51 -0
  38. data/spec/lib/serp_metrics/commands_spec.rb +62 -0
  39. data/spec/lib/serp_metrics/response_spec.rb +9 -0
  40. data/spec/lib/serp_metrics/version_spec.rb +8 -0
  41. data/spec/lib/serp_metrics_spec.rb +14 -0
  42. data/spec/spec_helper.rb +61 -0
  43. metadata +143 -0
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://api.serpmetrics.com/priority/add
6
+ body:
7
+ encoding: US-ASCII
8
+ string: key=h31x%25sd22hgjd2s&ts=1363584772&auth=lROO29qiF4QDoLetbhqb2gKopwnfB%2Bo%2F3g7RGDPcXx8%3D&params=%7B%22keyword%22%3A%22restaurants%22%2C%22engines%22%3A%5B%22google_en-us%22%5D%2C%22location%22%3A%22Nashville%22%7D
9
+ headers:
10
+ Content-Type:
11
+ - application/x-www-form-urlencoded
12
+ response:
13
+ status:
14
+ code: 201
15
+ message: Created
16
+ headers:
17
+ Server:
18
+ - nginx
19
+ Date:
20
+ - Mon, 18 Mar 2013 05:35:51 GMT
21
+ Content-Type:
22
+ - application/json; charset=UTF-8
23
+ Content-Length:
24
+ - '168'
25
+ Connection:
26
+ - keep-alive
27
+ Cache-Control:
28
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
29
+ Expires:
30
+ - Thu, 19 Nov 1981 08:52:00 GMT
31
+ Pragma:
32
+ - no-cache
33
+ Set-Cookie:
34
+ - app=pe19h26kipb7om3fpl84ai2uf6; path=/; HttpOnly
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ! '{"status":"ok","data":[{"phrase":"restaurants","engine_code":"google_en-us","priority_id":"5146a7effc9f6ec52b000013","location":"Nashville"}],"request_time":1363585108}'
38
+ http_version: !!null
39
+ recorded_at: Mon, 18 Mar 2013 05:32:52 GMT
40
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://api.serpmetrics.com/priority/add
6
+ body:
7
+ encoding: US-ASCII
8
+ string: key=h31x%25sd22hgjd2s&ts=1363584772&auth=lROO29qiF4QDoLetbhqb2gKopwnfB%2Bo%2F3g7RGDPcXx8%3D&params=%7B%22keyword%22%3A%22restaurants%22%2C%22engines%22%3A%5B%22google_en-us%22%5D%7D
9
+ headers:
10
+ Content-Type:
11
+ - application/x-www-form-urlencoded
12
+ response:
13
+ status:
14
+ code: 201
15
+ message: Created
16
+ headers:
17
+ Server:
18
+ - nginx
19
+ Date:
20
+ - Mon, 18 Mar 2013 05:35:51 GMT
21
+ Content-Type:
22
+ - application/json; charset=UTF-8
23
+ Content-Length:
24
+ - '145'
25
+ Connection:
26
+ - keep-alive
27
+ Cache-Control:
28
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
29
+ Expires:
30
+ - Thu, 19 Nov 1981 08:52:00 GMT
31
+ Pragma:
32
+ - no-cache
33
+ Set-Cookie:
34
+ - app=gu8a855sid6reic25r744mlev6; path=/; HttpOnly
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ! '{"status":"ok","data":[{"phrase":"restaurants","engine_code":"google_en-us","priority_id":"5146a7effc9f6ec52b000013"}],"request_time":1363585109}'
38
+ http_version: !!null
39
+ recorded_at: Mon, 18 Mar 2013 05:32:52 GMT
40
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,79 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://api.serpmetrics.com/priority/add
6
+ body:
7
+ encoding: US-ASCII
8
+ string: key=h31x%25sd22hgjd2s&ts=1363584772&auth=lROO29qiF4QDoLetbhqb2gKopwnfB%2Bo%2F3g7RGDPcXx8%3D&params=%7B%22keyword%22%3A%22restaurants%22%2C%22engines%22%3A%5B%22google_en-us%22%5D%7D
9
+ headers:
10
+ Content-Type:
11
+ - application/x-www-form-urlencoded
12
+ response:
13
+ status:
14
+ code: 201
15
+ message: Created
16
+ headers:
17
+ Server:
18
+ - nginx
19
+ Date:
20
+ - Mon, 18 Mar 2013 05:35:49 GMT
21
+ Content-Type:
22
+ - application/json; charset=UTF-8
23
+ Content-Length:
24
+ - '145'
25
+ Connection:
26
+ - keep-alive
27
+ Cache-Control:
28
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
29
+ Expires:
30
+ - Thu, 19 Nov 1981 08:52:00 GMT
31
+ Pragma:
32
+ - no-cache
33
+ Set-Cookie:
34
+ - app=68i5uv8hoc2deqm91hrdb4smo1; path=/; HttpOnly
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ! '{"status":"ok","data":[{"phrase":"restaurants","engine_code":"google_en-us","priority_id":"5146a7effc9f6ec52b000013"}],"request_time":1363585107}'
38
+ http_version: !!null
39
+ recorded_at: Mon, 18 Mar 2013 05:32:52 GMT
40
+ - request:
41
+ method: post
42
+ uri: http://api.serpmetrics.com/priority/status
43
+ body:
44
+ encoding: US-ASCII
45
+ string: key=h31x%25sd22hgjd2s&ts=1363584772&auth=lROO29qiF4QDoLetbhqb2gKopwnfB%2Bo%2F3g7RGDPcXx8%3D&params=%7B%22priority_id%22%3A%225146a7effc9f6ec52b000013%22%7D
46
+ headers:
47
+ Content-Type:
48
+ - application/x-www-form-urlencoded
49
+ response:
50
+ status:
51
+ code: 404
52
+ message: Not Found
53
+ headers:
54
+ Server:
55
+ - nginx
56
+ Date:
57
+ - Mon, 18 Mar 2013 05:35:50 GMT
58
+ Content-Type:
59
+ - application/json; charset=UTF-8
60
+ Content-Length:
61
+ - '97'
62
+ Connection:
63
+ - keep-alive
64
+ Vary:
65
+ - Accept-Encoding
66
+ Cache-Control:
67
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
68
+ Expires:
69
+ - Thu, 19 Nov 1981 08:52:00 GMT
70
+ Pragma:
71
+ - no-cache
72
+ Set-Cookie:
73
+ - app=vs805231hhsur4hjeoi21uq385; path=/; HttpOnly
74
+ body:
75
+ encoding: US-ASCII
76
+ string: ! '{"status":"error","message":"Currently in queue, please retry shortly","request_time":1363585108}'
77
+ http_version: !!null
78
+ recorded_at: Mon, 18 Mar 2013 05:32:52 GMT
79
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe SerpMetrics::Client do
4
+ it "provides accessors for key" do
5
+ instance = described_class.new
6
+ instance.key = "61dcaafa-5775-4905-b15a-c0dddb323038"
7
+ instance.key.should == "61dcaafa-5775-4905-b15a-c0dddb323038"
8
+ end
9
+
10
+ it "provides accessors for secret" do
11
+ instance = described_class.new
12
+ instance.secret = "4d5c3bb1-b274-4150-801b-7722d3427da1"
13
+ instance.secret.should == "4d5c3bb1-b274-4150-801b-7722d3427da1"
14
+ end
15
+
16
+ describe "configuration" do
17
+ it "performs block on client" do
18
+ instance = described_class.new
19
+ instance.configure do |client|
20
+ client.key = "acf08654-4694-4158-8b38-823233844d85"
21
+ client.secret = "eb9bb368-7c1f-41c0-afa1-c03fbfc2493b"
22
+ end
23
+ instance.key.should == "acf08654-4694-4158-8b38-823233844d85"
24
+ instance.secret.should == "eb9bb368-7c1f-41c0-afa1-c03fbfc2493b"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe SerpMetrics::CommandSets::Account, :vcr do
4
+ before do
5
+ api_configuration = YAML.load_file('spec/api_credentials.yml')
6
+ @client = SerpMetrics.client.configure do |client|
7
+ client.key = api_configuration['key']
8
+ client.secret = api_configuration['secret']
9
+ end
10
+ end
11
+
12
+ describe "credit" do
13
+ it "fetches credit information" do
14
+ response = @client.account.credit
15
+ response['status'].should == 'ok'
16
+ response['data'].should be_instance_of(Hash)
17
+ response['data']['serp_credit'].should_not be_nil
18
+ end
19
+ end
20
+
21
+ describe "time" do
22
+ it "fetches time" do
23
+ response = @client.account.time
24
+ response['request_time'].should_not be_nil
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe SerpMetrics::CommandSets::Engines, :vcr do
4
+ before do
5
+ api_configuration = YAML.load_file('spec/api_credentials.yml')
6
+ @client = SerpMetrics.client.configure do |client|
7
+ client.key = api_configuration['key']
8
+ client.secret = api_configuration['secret']
9
+ end
10
+ end
11
+
12
+ describe "codes" do
13
+ it "fetches search engine codes" do
14
+ response = @client.engines.codes
15
+ response['status'].should == 'ok'
16
+ response['data'].should be_instance_of(Array)
17
+ response['data'].should_not be_empty
18
+ response['data'][0]['engine_code'].should_not be_empty
19
+ response['data'][0]['name'].should_not be_empty
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe SerpMetrics::CommandSets::Flux, :vcr do
4
+ before do
5
+ api_configuration = YAML.load_file('spec/api_credentials.yml')
6
+ @client = SerpMetrics.client.configure do |client|
7
+ client.key = api_configuration['key']
8
+ client.secret = api_configuration['secret']
9
+ end
10
+ end
11
+
12
+ describe "flux" do
13
+ it "fetches flux trend" do
14
+ response = @client.flux.flux('google_en-us')
15
+ response['data'].should be_instance_of(Hash)
16
+ trend = response['data'].first
17
+ trend.should be_instance_of(Array)
18
+ trend.length.should == 2
19
+ trend[0].should be_instance_of(String)
20
+ trend[1].should be_instance_of(Fixnum)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe SerpMetrics::CommandSets::Keywords, :vcr do
4
+ before do
5
+ api_configuration = YAML.load_file('spec/api_credentials.yml')
6
+ @client = SerpMetrics.client.configure do |client|
7
+ client.key = api_configuration['key']
8
+ client.secret = api_configuration['secret']
9
+ end
10
+ end
11
+
12
+ after do
13
+ response = SerpMetrics.client.keywords.all
14
+ response['data'].each do |keyword_id, keyword_details|
15
+ SerpMetrics.client.keywords.remove(keyword_id)
16
+ end
17
+
18
+ # Fail if there are remaining keywords after attempt to remove them.
19
+ response = SerpMetrics.client.keywords.all
20
+ response['data'].should be_empty
21
+ end
22
+
23
+ describe "add" do
24
+ it "adds keyword" do
25
+ response = @client.keywords.add("restaurants", ['google_en-us'])
26
+ response['status'].should == 'ok'
27
+
28
+ keyword = response['data']
29
+ keyword['keyword'].should == "restaurants"
30
+ keyword['engines'].should == ['google_en-us']
31
+ keyword['keyword_id'].should_not be_empty
32
+ end
33
+ end
34
+
35
+ describe "remove" do
36
+ before do
37
+ response = @client.keywords.add("restaurants", ['google_en-us'])
38
+ @keyword_id = response['data']['keyword_id']
39
+ end
40
+
41
+ it "removes keyword" do
42
+ response = @client.keywords.remove(@keyword_id)
43
+ response['status'].should == 'ok'
44
+ keyword = response['data'].first
45
+ keyword['status'].should == 'ok'
46
+
47
+ # Verify that there is nothing left to remove.
48
+ response = @client.keywords.remove(@keyword_id)
49
+ response['status'].should == 'ok'
50
+ keyword = response['data'].first
51
+ keyword['status'].should == 'failed'
52
+ end
53
+ end
54
+
55
+ describe "check" do
56
+ before do
57
+ response = @client.keywords.add("restaurants", ['google_en-us'])
58
+ @keyword_id = response['data']['keyword_id']
59
+ end
60
+
61
+ it "retrieves checks" do
62
+ response = @client.keywords.check(@keyword_id, 'google_en-us')
63
+ response['data'].should_not be_empty
64
+ response['data']['checks'].should be_instance_of(Hash)
65
+ end
66
+ end
67
+
68
+ describe "serp" do
69
+ it "retrieves serp for check" do
70
+ response = @client.keywords.serp("03bcc63a-dc00-4a41-8010-4fc3346e85b5")
71
+ response['status'].should_not be_empty
72
+ end
73
+ end
74
+
75
+ describe "all" do
76
+ before do
77
+ @client.keywords.add("restaurants", ['google_en-us'])
78
+ end
79
+
80
+ it "retrieves keywords" do
81
+ response = @client.keywords.all
82
+
83
+ response['status'].should == 'ok'
84
+ keyword = response['data'].first
85
+ keyword[0].should_not be_empty
86
+ keyword[1]['phrase'].should == "restaurants"
87
+ keyword[1]['engines'].should == ['google_en-us']
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe SerpMetrics::CommandSets::Priorities, :vcr do
4
+ before do
5
+ api_configuration = YAML.load_file('spec/api_credentials.yml')
6
+ @client = SerpMetrics.client.configure do |client|
7
+ client.key = api_configuration['key']
8
+ client.secret = api_configuration['secret']
9
+ end
10
+ end
11
+
12
+ describe "add" do
13
+ context "without location" do
14
+ it "adds priority" do
15
+ response = @client.priorities.add("restaurants", ['google_en-us'])
16
+ response['status'].should == 'ok'
17
+
18
+ priority = response['data'].first
19
+ priority['phrase'].should == "restaurants"
20
+ priority['engine_code'].should == 'google_en-us'
21
+ priority['location'].should be_nil
22
+ priority['priority_id'].should_not be_empty
23
+ end
24
+ end
25
+
26
+ context "with location" do
27
+ it "adds priority" do
28
+ response = @client.priorities.add("restaurants", ['google_en-us'], "Nashville")
29
+ response['status'].should == 'ok'
30
+
31
+ priority = response['data'].first
32
+ priority['phrase'].should == "restaurants"
33
+ priority['engine_code'].should == 'google_en-us'
34
+ priority['location'].should == "Nashville"
35
+ priority['priority_id'].should_not be_empty
36
+ end
37
+ end
38
+ end
39
+
40
+ describe "get" do
41
+ it "checks priority" do
42
+ response = @client.priorities.add("restaurants", ['google_en-us'])
43
+
44
+ priority = response['data'].first
45
+ priority_id = priority['priority_id']
46
+
47
+ response = @client.priorities.get(priority_id)
48
+ response['status'].should_not be_nil
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe SerpMetrics::Client do
4
+ before do
5
+ @client = described_class.new
6
+ end
7
+
8
+ describe ".keywords" do
9
+ it "assigns client for command set" do
10
+ @client.keywords.client.should be_equal(@client)
11
+ end
12
+
13
+ it "caches command set for client" do
14
+ old_command_set = @client.keywords
15
+ @client.keywords.should be_equal(old_command_set)
16
+ end
17
+ end
18
+
19
+ describe ".account" do
20
+ it "assigns client for command set" do
21
+ @client.account.client.should be_equal(@client)
22
+ end
23
+
24
+ it "caches command set for client" do
25
+ old_command_set = @client.account
26
+ @client.account.should be_equal(old_command_set)
27
+ end
28
+ end
29
+
30
+ describe ".priorities" do
31
+ it "assigns client for command set" do
32
+ @client.priorities.client.should be_equal(@client)
33
+ end
34
+
35
+ it "caches command set for client" do
36
+ old_command_set = @client.priorities
37
+ @client.priorities.should be_equal(old_command_set)
38
+ end
39
+ end
40
+
41
+ describe ".flux" do
42
+ it "assigns client for command set" do
43
+ @client.flux.client.should be_equal(@client)
44
+ end
45
+
46
+ it "caches command set for client" do
47
+ old_command_set = @client.flux
48
+ @client.flux.should be_equal(old_command_set)
49
+ end
50
+ end
51
+
52
+ describe ".engines" do
53
+ it "assigns client for command set" do
54
+ @client.engines.client.should be_equal(@client)
55
+ end
56
+
57
+ it "caches command set for client" do
58
+ old_command_set = @client.engines
59
+ @client.engines.should be_equal(old_command_set)
60
+ end
61
+ end
62
+ end