Sha256: c4cafb0d7fc8a7d0cc6ca97709e997534d60f87c8c8824dd3c656aca1ce380bf

Contents?: true

Size: 668 Bytes

Versions: 1

Compression:

Stored size: 668 Bytes

Contents

require "faraday"
require "json"

module Sharedcount
	class API

		attr_accessor :connection, :endpoint, :apikey

		def initialize(endpoint = nil, apikey = nil)
			self.endpoint = endpoint || Sharedcount.config.endpoint
			self.apikey = apikey || Sharedcount.config.apikey
	    self.connection = Faraday.new(:url => self.endpoint) do |faraday|
	      faraday.request  :url_encoded                            
	      faraday.adapter  Faraday.default_adapter 
	    end
		end

		def fetch(url)
      response = self.connection.get "/?apikey=#{self.apikey}&url=#{url}"
      raw_data = JSON.parse(response.body)
      return Sharedcount::Data.new(raw_data)
		end

	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sharedcount-0.0.1 lib/sharedcount/api.rb