places_scout 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f440cab434622af128a6384ee030633dc851ae50
4
- data.tar.gz: 975f83b748566573af6fe9f863c11fb71b3e57a4
3
+ metadata.gz: f468cfc1af5525677fca6bc11d2b44f06b8efa48
4
+ data.tar.gz: 5e9d854364d7f21d466acf8c17e9c17d9b2073f1
5
5
  SHA512:
6
- metadata.gz: 83bde4dbc82c9916dad408f2cc72a522dfa05947dd1dfa76e9c917124de77948495073ccbfb814e4ce6952ebe73c4e106accfd541896b028ded2ebe1b73d24c3
7
- data.tar.gz: 64c5b786c32045922aa72979de9fec36c83f5307c225b30d664eee63eb6cfd9786ccf43c3cb9cd3b22e713da0e21c8be3bdc1e15d07d01f0a280c58ca3eada21
6
+ metadata.gz: 1afacba91e4525ecb062ddcd6ba3a5c6237d18bf054e8843c427cc7367397c0a6a536d9f54d4b50fc84d9742a9775f8b841d44f409d212e4361def11c39d173e
7
+ data.tar.gz: 6f85e09a03769e81d7bbcccdc598f86a2123d72625ac43eaef66d2458053f89f2ba3b4190c9d6756d8de9875fd55d732086599c88eaa0b0c85fc16ed51487bce
data/.gitignore CHANGED
@@ -7,4 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
- test.rb
10
+ test.rb
11
+ *.gem
data/README.md CHANGED
@@ -70,6 +70,97 @@ testcon.get_ranking_reports(:reportid => 'report-id', :runs => true, :newest =>
70
70
  ```ruby
71
71
  testcon.get_status #Grab the status of all reports
72
72
  ```
73
+ ## Sample Code
74
+ ```ruby
75
+ clients = get_clients_and_ids(testcon) #Grab all clients
76
+ add_report_ids(clients, testcon) #Grab report ID's per client
77
+ add_report_run_ids(clients, testcon) # Grab run per report
78
+ get_run_rankings(clients, testcon) # Grab results per run
79
+ puts clients[0][:reports][0][:runs][0][:rankings][0] # Return first client, report, run, keyword ranks
80
+
81
+
82
+ def get_clients_and_ids(testcon)
83
+ clients = []
84
+ results = testcon.get_clients()
85
+
86
+ results.each do |result|
87
+ result['items'].each do |item|
88
+ clients.push(:name => item['name'], :id => item['id'])
89
+ end
90
+ end
91
+
92
+ return clients
93
+ end
94
+
95
+ def add_report_ids(clients, testcon)
96
+ clients.each do |client|
97
+ report_ids = []
98
+ rankings = testcon.get_ranking_reports(:clientid => client[:id])
99
+ rankings.each do |rank|
100
+ rank['items'].each do |item|
101
+ report_ids.push(:id => item['rankingReport']['id'])
102
+ end
103
+ end
104
+ client[:reports] = report_ids
105
+ end
106
+ return clients
107
+ end
108
+
109
+ def add_report_run_ids(clients, testcon)
110
+ clients.each do |client|
111
+ run_id_date = []
112
+ client[:reports].each do |report|
113
+ report_runs = testcon.get_ranking_reports(:reportid => report[:id], :rundates => true)
114
+ report_runs.each do |runs|
115
+ runs['items'].each do |run|
116
+ run_id_date.push(:runID => run['runId'], :runDate => parse_date(run['runDate']))
117
+ end
118
+ end
119
+ report[:runs] = run_id_date
120
+ end
121
+ end
122
+ end
123
+
124
+ def get_run_rankings(clients, testcon)
125
+ clients.each do |client|
126
+ client[:reports].each do |report|
127
+ report[:runs].each do |run|
128
+ keyword_rankings = []
129
+ report_runs = testcon.get_ranking_reports(:reportid => report[:id], :runs => true, :runid => run[:runID])
130
+ report_runs.each do |report_run|
131
+ report_run['keywordRankingResults'].each do |results|
132
+ results[1].each do |result|
133
+ google_rankings = []
134
+ bing_rankings = []
135
+ result['keywordSearch']['keyword']
136
+
137
+ result['googleOrganicRankings'].each do |g_rank|
138
+ google_rankings.push(g_rank['rank'])
139
+ end
140
+
141
+ result['bingOrganicRankings'].each do |b_rank|
142
+ bing_rankings.push(b_rank['rank'])
143
+ end
144
+
145
+ keyword_rankings.push(:keyword => result['keywordSearch']['keyword'], :google_rank => google_rankings, :bing_rank => bing_rankings)
146
+
147
+ end
148
+ end
149
+ end
150
+ run[:rankings] = keyword_rankings
151
+ end
152
+ end
153
+ end
154
+ end
155
+
156
+
157
+ def parse_date(datestring)
158
+ seconds_since_epoch = datestring.scan(/[0-9]+/)[0].to_i / 1000.0
159
+ return Time.at(seconds_since_epoch)
160
+ end
161
+
162
+ ```
163
+
73
164
 
74
165
  ## Development
75
166
 
@@ -13,7 +13,7 @@ module PlacesScout
13
13
 
14
14
  def initialize(u, p)
15
15
  @url = 'https://apihost1.placesscout.com'
16
- $auth = 'Basic ' + Base64.encode64(u + ':' + p).chomp
16
+ @auth = 'Basic ' + Base64.encode64(u + ':' + p).chomp
17
17
  end
18
18
 
19
19
  def parse_json(response)
@@ -28,11 +28,11 @@ module PlacesScout
28
28
  params = {}
29
29
  params[:page] = opts[:page] || 1
30
30
  params[:size] = opts[:size] || MAX_PAGE_SIZE
31
- total_size = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body['total'] || 1
31
+ total_size = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => @auth)).body['total'] || 1
32
32
  total_pages = (opts[:page]) ? 1 : (total_size/params[:size].to_f).ceil
33
33
 
34
34
  while total_pages > 0
35
- response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body
35
+ response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => @auth)).body
36
36
  results.push(response)
37
37
  params[:page] += 1 unless opts[:page]
38
38
  total_pages -= 1
@@ -50,11 +50,11 @@ module PlacesScout
50
50
  params[:size] = opts[:size] || MAX_PAGE_SIZE
51
51
  params[:clientid] = opts[:clientid]
52
52
  location = opts[:locationid]
53
- total_size = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body['total'] || 1
53
+ total_size = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => @auth)).body['total'] || 1
54
54
  total_pages = (opts[:page]) ? 1 : (total_size/params[:size].to_f).ceil
55
55
 
56
56
  while total_pages > 0
57
- response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body
57
+ response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => @auth)).body
58
58
  results.push(response)
59
59
  params[:page] += 1 unless opts[:page]
60
60
  total_pages -= 1
@@ -70,11 +70,11 @@ module PlacesScout
70
70
  params[:size] = opts[:size] || MAX_PAGE_SIZE
71
71
  params[:clientid] = opts[:clientid]
72
72
  path = "/clientfolders"
73
- total_size = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body['total'] || 1
73
+ total_size = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => @auth)).body['total'] || 1
74
74
  total_pages = (opts[:page]) ? 1 : (total_size/params[:size].to_f).ceil
75
75
 
76
76
  while total_pages > 0
77
- response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body
77
+ response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => @auth)).body
78
78
  results.push(response)
79
79
  params[:page] += 1 unless opts[:page]
80
80
  total_pages -= 1
@@ -114,11 +114,11 @@ module PlacesScout
114
114
  params[:GoogleLocation] = opts[:googlelocation] if opts[:googlelocation]
115
115
  params[:page] = opts[:page] || 1
116
116
  params[:size] = opts[:size] || MAX_PAGE_SIZE
117
- total_size = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body['total'] || 1
117
+ total_size = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => @auth)).body['total'] || 1
118
118
  total_pages = (opts[:page] || opts[:locationid]) ? 1 : (total_size/params[:size].to_f).ceil
119
119
 
120
120
  while total_pages > 0
121
- response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body
121
+ response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => @auth)).body
122
122
  results.push(response)
123
123
  params[:page] += 1 unless opts[:page]
124
124
  total_pages -= 1
@@ -131,7 +131,7 @@ module PlacesScout
131
131
  params = {}
132
132
  reportid = "/#{opts[:reportid]}" || ""
133
133
  path = "/status/getreportstatus"
134
- response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body
134
+ response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => @auth)).body
135
135
  end
136
136
 
137
137
 
@@ -1,3 +1,3 @@
1
1
  module PlacesScout
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "bundler", "~> 1.13"
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
 
36
- spec.add_dependency "rest-client", "~> 1.8.0"
37
- spec.add_dependency "json", "~> 1.8.1"
36
+ spec.add_dependency "rest-client", "~> 2.0.2"
37
+ spec.add_dependency "json", "~> 2.1.0"
38
38
 
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: places_scout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Hoskison
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-09 00:00:00.000000000 Z
11
+ date: 2017-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.8.0
47
+ version: 2.0.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.8.0
54
+ version: 2.0.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: json
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.8.1
61
+ version: 2.1.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.8.1
68
+ version: 2.1.0
69
69
  description: Places Scout API
70
70
  email:
71
71
  - mhoskison@etnainteractive.com