places_scout 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5fb4545fabed5b244cdf7286a4ec0c334da46bf6
4
+ data.tar.gz: b1656588dbe562538908cca4a3dc6b660c72126c
5
+ SHA512:
6
+ metadata.gz: 3eb7b5ebe099c6aa822ad8f5eb9dcb63d6ca49020b352091817df06e6ffb0981135b1dc1427b860eccd99dd02c1f29db6af3e780d377628520e86c8c7edc7573
7
+ data.tar.gz: e658722d41fd01a4b9298d7c4a27d4c139092eb46a46f5c9725ec7c85e1bfa56083a0bd974ed9564b41a49d5088aa2dbf1981666ca972be5b63e1f7e0d348242
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in places_scout.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Michael Hoskison
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,88 @@
1
+ # PlacesScout
2
+
3
+ A gem to interact with the Places Scout API. https://www.placesscout.com/api
4
+ Check the usage section for what's currently implemented.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'places_scout'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install places_scout
21
+
22
+ ## Usage
23
+
24
+ You can add :size & :page as parameters to grab specific size/page to the calls below. The maximum size supported by the API is 100.
25
+ ```ruby
26
+ get_ranking_reports() # Defaults to returning all pages with 100 results each
27
+ get_ranking_reports(:size => '10') # Returns all pages with 10 results each
28
+ get_ranking_reports(:size => '5', page => '5') # Returns only the 5th page
29
+ ```
30
+ ### Connecting to the API
31
+ ```ruby
32
+ testcon = PlacesScout::Api.new("username", "password")
33
+ ```
34
+ ### Clients
35
+ ```ruby
36
+ testcon.get_clients() # Grab all clients.
37
+ testcon.get_clients(:clientid => 'client-id') #Grab specific client
38
+ ```
39
+ ### Locations
40
+ ```ruby
41
+ testcon.get_client_locations() # Grab all client locations.
42
+ testcon.get_client_locations(:clientid => 'client-id') #Grab locations for specific client
43
+ testcon.get_client_locations(:locationid => 'location-id') #Grab by location id
44
+ ```
45
+ ### Folders
46
+ ```ruby
47
+ testcon.get_client_folders()#Grab all client folders.
48
+ testcon.get_client_folders(:clientid => 'client-id') #Grab folder off client id
49
+ ```
50
+ ### Rank Reports
51
+ ```ruby
52
+ testcon.get_ranking_reports #Grab a list of all ranking reports.
53
+ testcon.get_ranking_reports(:all => true) #Grab all ranking report data.
54
+ testcon.get_ranking_reports(:clientid => 'client-id') #Grab Rank reports for a specific client
55
+ testcon.get_ranking_reports(:clientid => 'client-id', :locationid=> 'location-id') # Grab specific location for specific client
56
+ testcon.get_ranking_reports(:reportid => 'report-id') #Grab a specific ranking report
57
+ testcon.get_ranking_reports(:reportid => 'report-id', :historical => true) #Return chart for average rankings over time
58
+ testcon.get_ranking_reports(:reportid => 'report-id', :historical => true, :keywords => true) #Return chart for keyword rankings over time
59
+ testcon.get_ranking_reports(:reportid => 'report-id', :rundates => true) # Return run dates and ID's for a report
60
+ testcon.get_ranking_reports(:reportid => 'report-id', :runs => true) #Grab the runs for a report
61
+ testcon.get_ranking_reports(:reportid => 'report-id', :runs => true, :runid => 'run-id') #Grab a specific report run
62
+ testcon.get_ranking_reports(:reportid => 'report-id', :runs => true, :runid => 'run-id', :keywordresults => true) #Grab a specific report run keyword results
63
+ testcon.get_ranking_reports(:reportid => 'report-id', :runs => true, :runid => 'run-id', :keywordresults => true, :keywordresultsid => 'keyword-results-id') #Grab a specific keyword result for a specific report run
64
+ testcon.get_ranking_reports(:reportid => 'report-id', :runs => true, :runid => 'run-id', :keywordserpscreenshot => 'adhesion treatment' , :googlelocation => 'San Luis Obispo, CA') #Google Organic SERP Page
65
+ testcon.get_ranking_reports(:reportid => 'report-id', :runs => true, :runid => 'run-id', :summary => true) # Grab summary metrics
66
+ testcon.get_ranking_reports(:reportid => 'report-id', :runs => true, :newest => true) # Grab newest if :newest => true. Grab oldest if :newest => false
67
+ ```
68
+
69
+ ### Status
70
+ ```ruby
71
+ testcon.get_status #Grab the status of all reports
72
+ ```
73
+
74
+ ## Development
75
+
76
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
+
78
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mhoskiso/places_scout.
83
+
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
88
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "places_scout"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,143 @@
1
+ require 'bundler/setup'
2
+ require "places_scout/version"
3
+ require "base64"
4
+ require 'json'
5
+ require 'ostruct'
6
+
7
+ require 'rest-client'
8
+
9
+ module PlacesScout
10
+ class Api
11
+ # RestClient.log = 'stdout' #Debugging API calls
12
+ MAX_PAGE_SIZE = '100'
13
+
14
+ def initialize(u, p)
15
+ @url = 'https://apihost1.placesscout.com'
16
+ $auth = 'Basic ' + Base64.encode64(u + ':' + p).chomp
17
+ end
18
+
19
+ def parse_json(response)
20
+ body = JSON.parse(response.to_str) if response.code == 200
21
+ OpenStruct.new(code: response.code, body: body)
22
+ end
23
+
24
+ # /clients
25
+ def get_clients( opts = {})
26
+ path = "/clients/#{opts[:clientid]}"
27
+ results = []
28
+ params = {}
29
+ params[:page] = opts[:page] || 1
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
32
+ total_pages = (opts[:page]) ? 1 : (total_size/params[:size].to_f).ceil
33
+
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
36
+ results.push(response)
37
+ params[:page] += 1 unless opts[:page]
38
+ total_pages -= 1
39
+ end
40
+
41
+ return results
42
+ end
43
+
44
+ # Client Locations
45
+ def get_client_locations( opts = {})
46
+ path = "/clientlocations/#{opts[:locationid]}"
47
+ results = []
48
+ params = {}
49
+ params[:page] = opts[:page] || 1
50
+ params[:size] = opts[:size] || MAX_PAGE_SIZE
51
+ params[:clientid] = opts[:clientid]
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
54
+ total_pages = (opts[:page]) ? 1 : (total_size/params[:size].to_f).ceil
55
+
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
58
+ results.push(response)
59
+ params[:page] += 1 unless opts[:page]
60
+ total_pages -= 1
61
+ end
62
+ return results
63
+ end
64
+
65
+ # /folders
66
+ def get_client_folders( opts = {})
67
+ results = []
68
+ params = {}
69
+ params[:page] = opts[:page] || 1
70
+ params[:size] = opts[:size] || MAX_PAGE_SIZE
71
+ params[:clientid] = opts[:clientid]
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
74
+ total_pages = (opts[:page]) ? 1 : (total_size/params[:size].to_f).ceil
75
+
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
78
+ results.push(response)
79
+ params[:page] += 1 unless opts[:page]
80
+ total_pages -= 1
81
+ end
82
+ return results
83
+ end
84
+
85
+ # /rankingreports
86
+ def get_ranking_reports( opts = {})
87
+ results = []
88
+ params = {}
89
+ reportid = "/#{opts[:reportid]}" || ""
90
+ params[:locationid] = opts[:locationid] || ""
91
+ params[:clientid] = opts[:clientid] || ""
92
+ all = (opts[:all]) ? "/all" : ""
93
+ historical = (opts[:historical] && opts[:reportid] && all == "") ? "/historical" : ""
94
+ keywords = (opts[:historical] && opts[:reportid] && opts[:keywords] && all == "") ? "/keywords" : ""
95
+ rundates = (opts[:rundates] && opts[:reportid] && all == "") ? "/rundatesandids" : ""
96
+ runs = (opts[:runs] && opts[:reportid] && rundates == "" && all == "") ? "/runs" : ""
97
+ runid = (opts[:runid] && opts[:runs] && rundates == "" && all == "") ? "/#{opts[:runid]}" : ""
98
+ summary = (opts[:summary] && opts[:runid] && opts[:runs] && rundates == "" && all == "") ? "/summarymetrics" : ""
99
+ keywordresults = (opts[:keywordresults] && opts[:runid] && opts[:runs] && opts[:reportid] && rundates =="" && summary == "" && all == "") ? "/keywordsearchresults" : ""
100
+ keywordresultsid = (opts[:keywordresultsid] && opts[:keywordresults] && opts[:runid] && opts[:runs] && opts[:reportid] && rundates =="" && summary == "" && all == "") ? "/#{opts[:keywordresultsid]}" : ""
101
+ keywordserpscreenshot = (opts[:runid] && opts[:runs] && opts[:reportid] && rundates == "" && keywordresults == "" && keywordresultsid == "" && summary == "" && all == "") ? "/keywordserpscreenshot" : ""
102
+
103
+ newest = case opts[:newest]
104
+ when opts[:newest] = true
105
+ "/newest"
106
+ when opts[:newest] = false
107
+ "/oldest"
108
+ else
109
+ ""
110
+ end
111
+
112
+ path = (opts[:clientid] && params[:locationid] == "" && all == "") ? "/rankingreports/#{opts[:clientid]}/allbyclient" : "/rankingreports#{all}#{opts[:reportid]}#{rundates}#{runs}#{newest}#{runid}#{summary}#{historical}#{keywords}#{keywordresults}#{keywordresultsid}#{keywordserpscreenshot}"
113
+ params[:Keyword] = opts[:keywordserpscreenshot] if opts[:keywordserpscreenshot]
114
+ params[:GoogleLocation] = opts[:googlelocation] if opts[:googlelocation]
115
+ params[:page] = opts[:page] || 1
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
118
+ total_pages = (opts[:page] || opts[:locationid]) ? 1 : (total_size/params[:size].to_f).ceil
119
+
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
122
+ results.push(response)
123
+ params[:page] += 1 unless opts[:page]
124
+ total_pages -= 1
125
+ end
126
+ return results
127
+ end
128
+
129
+ def get_status( opts = {})
130
+ results = []
131
+ params = {}
132
+ reportid = "/#{opts[:reportid]}" || ""
133
+ path = "/status/getreportstatus"
134
+ response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body
135
+ end
136
+
137
+
138
+
139
+
140
+
141
+ end
142
+
143
+ end
@@ -0,0 +1,3 @@
1
+ module PlacesScout
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'places_scout/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "places_scout"
8
+ spec.version = PlacesScout::VERSION
9
+ spec.authors = ["Michael Hoskison"]
10
+ spec.email = ["mhoskison@etnainteractive.com"]
11
+
12
+ spec.summary = %q{Used to access the Places Scout api}
13
+ spec.description = %q{Places Scout API}
14
+ spec.homepage = "https://github.com/mhoskiso/places_scout"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.13"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+
36
+ spec.add_dependency "rest-client", "~> 1.8.0"
37
+ spec.add_dependency "json", "~> 1.8.1"
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: places_scout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Hoskison
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-03 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.8.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.1
69
+ description: Places Scout API
70
+ email:
71
+ - mhoskison@etnainteractive.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - lib/places_scout.rb
84
+ - lib/places_scout/version.rb
85
+ - places_scout.gemspec
86
+ homepage: https://github.com/mhoskiso/places_scout
87
+ licenses:
88
+ - MIT
89
+ metadata:
90
+ allowed_push_host: https://rubygems.org
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Used to access the Places Scout api
111
+ test_files: []