class Serpscan::API

Constants

BASE_URL

Public Class Methods

delete(path) click to toggle source
# File lib/serpscan/api.rb, line 17
def delete(path)
  RestClient.delete(api_url(path))
end
get(path, options = {}) click to toggle source
# File lib/serpscan/api.rb, line 8
def get(path, options = {})
  url = api_url(path)
  if options[:params]
    url += "&#{querify(options[:params])}"
  end

  normalize_response RestClient.get(url)
end
post(path, options = {}) click to toggle source
# File lib/serpscan/api.rb, line 21
def post(path, options = {})
  normalize_response RestClient.post(api_url(path), options[:params].to_json)
end
put(path, options = {}) click to toggle source
# File lib/serpscan/api.rb, line 25
def put(path, options = {})
  normalize_response RestClient.put(api_url(path), options[:params].to_json, content_type: :json)
end

Private Class Methods

api_url(path) click to toggle source
# File lib/serpscan/api.rb, line 35
def api_url(path)
  "#{BASE_URL}#{tokenize(path)}"
end
normalize_response(response) click to toggle source
# File lib/serpscan/api.rb, line 31
def normalize_response(response)
  JSON.parse(response)
end
querify(hash) click to toggle source
# File lib/serpscan/api.rb, line 39
def querify(hash)
  hash.map { |k, v| "#{k}=#{v}".to_s }.join('&')
end
tokenize(path) click to toggle source
# File lib/serpscan/api.rb, line 43
def tokenize(path)
  param_separator = path.include?('?') ? '&' : '?'
  path += "#{param_separator}token=#{Serpscan.api_key}"
end