class SimilarWeb::Client

Attributes

api_key[RW]
http_client[R]

Public Class Methods

new(args = {}) click to toggle source
# File lib/similarweb/client.rb, line 20
def initialize(args = {})
  args.each do |key, value|
    send(:"#{key}=", value)
  end
  @http_client = Faraday.new(:url => base_url)
end

Public Instance Methods

base_url() click to toggle source
# File lib/similarweb/client.rb, line 27
def base_url
  @base_url ||= "https://api.similarweb.com/Site/"
end

Protected Instance Methods

parse_response(response) click to toggle source
# File lib/similarweb/client.rb, line 38
def parse_response(response)
  JSON(response.body)
end
request(uri, params = {}, http_method = :get) click to toggle source
# File lib/similarweb/client.rb, line 33
def request(uri, params = {}, http_method = :get)
  url = "#{uri}?Format=JSON&UserKey=#{api_key}&#{to_query(params)}"
  parse_response(http_client.public_send(http_method, url))
end
to_query(params) click to toggle source
# File lib/similarweb/client.rb, line 42
def to_query(params)
  params.map { |key, value| "#{key}=#{value}" }.join("&")
end