Class: PlacesScout::Api
- Inherits:
-
Object
- Object
- PlacesScout::Api
- Defined in:
- lib/places_scout.rb
Constant Summary collapse
- MAX_PAGE_SIZE =
RestClient.log = 'stdout' #Debugging API calls
'100'
Instance Method Summary collapse
-
#get_client_folders(opts = {}) ⇒ Object
/folders.
-
#get_client_locations(opts = {}) ⇒ Object
Client Locations.
-
#get_clients(opts = {}) ⇒ Object
/clients.
-
#get_ranking_reports(opts = {}) ⇒ Object
/rankingreports.
- #get_status(opts = {}) ⇒ Object
-
#initialize(u, p) ⇒ Api
constructor
A new instance of Api.
- #parse_json(response) ⇒ Object
Constructor Details
#initialize(u, p) ⇒ Api
Returns a new instance of Api.
14 15 16 17 |
# File 'lib/places_scout.rb', line 14 def initialize(u, p) @url = 'https://apihost1.placesscout.com' $auth = 'Basic ' + Base64.encode64(u + ':' + p).chomp end |
Instance Method Details
#get_client_folders(opts = {}) ⇒ Object
/folders
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/places_scout.rb', line 66 def get_client_folders( opts = {}) results = [] params = {} params[:page] = opts[:page] || 1 params[:size] = opts[:size] || MAX_PAGE_SIZE params[:clientid] = opts[:clientid] path = "/clientfolders" total_size = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body['total'] || 1 total_pages = (opts[:page]) ? 1 : (total_size/params[:size].to_f).ceil while total_pages > 0 response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body results.push(response) params[:page] += 1 unless opts[:page] total_pages -= 1 end return results end |
#get_client_locations(opts = {}) ⇒ Object
Client Locations
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/places_scout.rb', line 45 def get_client_locations( opts = {}) path = "/clientlocations/#{opts[:locationid]}" results = [] params = {} params[:page] = opts[:page] || 1 params[:size] = opts[:size] || MAX_PAGE_SIZE params[:clientid] = opts[:clientid] location = opts[:locationid] total_size = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body['total'] || 1 total_pages = (opts[:page]) ? 1 : (total_size/params[:size].to_f).ceil while total_pages > 0 response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body results.push(response) params[:page] += 1 unless opts[:page] total_pages -= 1 end return results end |
#get_clients(opts = {}) ⇒ Object
/clients
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/places_scout.rb', line 25 def get_clients( opts = {}) path = "/clients/#{opts[:clientid]}" results = [] params = {} params[:page] = opts[:page] || 1 params[:size] = opts[:size] || MAX_PAGE_SIZE total_size = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body['total'] || 1 total_pages = (opts[:page]) ? 1 : (total_size/params[:size].to_f).ceil while total_pages > 0 response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body results.push(response) params[:page] += 1 unless opts[:page] total_pages -= 1 end return results end |
#get_ranking_reports(opts = {}) ⇒ Object
/rankingreports
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/places_scout.rb', line 86 def get_ranking_reports( opts = {}) results = [] params = {} reportid = "/#{opts[:reportid]}" || "" params[:locationid] = opts[:locationid] || "" params[:clientid] = opts[:clientid] || "" all = (opts[:all]) ? "/all" : "" historical = (opts[:historical] && opts[:reportid] && all == "") ? "/historical" : "" keywords = (opts[:historical] && opts[:reportid] && opts[:keywords] && all == "") ? "/keywords" : "" rundates = (opts[:rundates] && opts[:reportid] && all == "") ? "/rundatesandids" : "" runs = (opts[:runs] && opts[:reportid] && rundates == "" && all == "") ? "/runs" : "" runid = (opts[:runid] && opts[:runs] && rundates == "" && all == "") ? "/#{opts[:runid]}" : "" summary = (opts[:summary] && opts[:runid] && opts[:runs] && rundates == "" && all == "") ? "/summarymetrics" : "" keywordresults = (opts[:keywordresults] && opts[:runid] && opts[:runs] && opts[:reportid] && rundates =="" && summary == "" && all == "") ? "/keywordsearchresults" : "" keywordresultsid = (opts[:keywordresultsid] && opts[:keywordresults] && opts[:runid] && opts[:runs] && opts[:reportid] && rundates =="" && summary == "" && all == "") ? "/#{opts[:keywordresultsid]}" : "" keywordserpscreenshot = (opts[:runid] && opts[:runs] && opts[:reportid] && rundates == "" && keywordresults == "" && keywordresultsid == "" && summary == "" && all == "") ? "/keywordserpscreenshot" : "" newest = case opts[:newest] when opts[:newest] = true "/newest" when opts[:newest] = false "/oldest" else "" end path = (opts[:clientid] && params[:locationid] == "" && all == "") ? "/rankingreports/#{opts[:clientid]}/allbyclient" : "/rankingreports#{all}#{reportid}#{rundates}#{runs}#{newest}#{runid}#{summary}#{historical}#{keywords}#{keywordresults}#{keywordresultsid}#{keywordserpscreenshot}" params[:Keyword] = opts[:keywordserpscreenshot] if opts[:keywordserpscreenshot] params[:GoogleLocation] = opts[:googlelocation] if opts[:googlelocation] params[:page] = opts[:page] || 1 params[:size] = opts[:size] || MAX_PAGE_SIZE total_size = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body['total'] || 1 total_pages = (opts[:page] || opts[:locationid]) ? 1 : (total_size/params[:size].to_f).ceil while total_pages > 0 response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body results.push(response) params[:page] += 1 unless opts[:page] total_pages -= 1 end return results end |
#get_status(opts = {}) ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/places_scout.rb', line 129 def get_status( opts = {}) results = [] params = {} reportid = "/#{opts[:reportid]}" || "" path = "/status/getreportstatus" response = parse_json(RestClient.get(@url+path, params: params, :content_type => 'application/json', :accept => 'application/json', :Authorization => $auth)).body end |
#parse_json(response) ⇒ Object
19 20 21 22 |
# File 'lib/places_scout.rb', line 19 def parse_json(response) body = JSON.parse(response.to_str) if response.code == 200 OpenStruct.new(code: response.code, body: body) end |