Class: Sharedcount::API
- Inherits:
-
Object
- Object
- Sharedcount::API
- Defined in:
- lib/sharedcount/api.rb
Instance Attribute Summary collapse
-
#apikey ⇒ Object
Returns the value of attribute apikey.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
Instance Method Summary collapse
- #fetch(url) ⇒ Object
-
#initialize(endpoint = nil, apikey = nil) ⇒ API
constructor
A new instance of API.
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
#apikey ⇒ Object
Returns the value of attribute apikey.
7 8 9 |
# File 'lib/sharedcount/api.rb', line 7 def apikey @apikey end |
#connection ⇒ Object
Returns the value of attribute connection.
7 8 9 |
# File 'lib/sharedcount/api.rb', line 7 def connection @connection end |
#endpoint ⇒ Object
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 |