Class: Sharedcount::API

Inherits:
Object
  • Object
show all
Defined in:
lib/sharedcount/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint = nil, apikey = nil) ⇒ API

Returns a new instance of API.



9
10
11
12
13
14
15
16
# File 'lib/sharedcount/api.rb', line 9

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

Instance Attribute Details

#apikeyObject

Returns the value of attribute apikey.



7
8
9
# File 'lib/sharedcount/api.rb', line 7

def apikey
  @apikey
end

#connectionObject

Returns the value of attribute connection.



7
8
9
# File 'lib/sharedcount/api.rb', line 7

def connection
  @connection
end

#endpointObject

Returns the value of attribute endpoint.



7
8
9
# File 'lib/sharedcount/api.rb', line 7

def endpoint
  @endpoint
end

Instance Method Details

#fetch(url) ⇒ Object



18
19
20
21
# File 'lib/sharedcount/api.rb', line 18

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