Class: Infosimples::Data::Client
- Inherits:
-
Object
- Object
- Infosimples::Data::Client
- Defined in:
- lib/infosimples/data/client.rb
Overview
Infosimples::Data::Client is a client for the Infosimples Data API.
Constant Summary collapse
- BASE_URL =
'https://data.infosimples.com/api/v1/:service.json'
Instance Attribute Summary collapse
-
#max_age ⇒ Object
Returns the value of attribute max_age.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#automate(service, args = {}) ⇒ Hash
Automate a service.
-
#billing ⇒ Array
Get billing statistics from your account.
-
#download_sites_urls(response) ⇒ Array
Download sites_urls from response.
-
#initialize(token, options = {}) ⇒ Infosimples::Data::Client
constructor
Create a Infosimples::Data API client.
-
#pricing ⇒ Array
Get prices for each service.
Constructor Details
#initialize(token, options = {}) ⇒ Infosimples::Data::Client
Create a Infosimples::Data API client.
19 20 21 22 23 |
# File 'lib/infosimples/data/client.rb', line 19 def initialize(token, = {}) self.token = token self.timeout = [:timeout] || 120 # 120 seconds self.max_age = [:max_age] || 86400 # 24 hours in seconds end |
Instance Attribute Details
#max_age ⇒ Object
Returns the value of attribute max_age.
6 7 8 |
# File 'lib/infosimples/data/client.rb', line 6 def max_age @max_age end |
#timeout ⇒ Object
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/infosimples/data/client.rb', line 6 def timeout @timeout end |
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/infosimples/data/client.rb', line 6 def token @token end |
Instance Method Details
#automate(service, args = {}) ⇒ Hash
Automate a service.
31 32 33 |
# File 'lib/infosimples/data/client.rb', line 31 def automate(service, args = {}) request(service, :multipart, args) end |
#billing ⇒ Array
Get billing statistics from your account.
38 39 40 |
# File 'lib/infosimples/data/client.rb', line 38 def billing request('billing', :get) end |
#download_sites_urls(response) ⇒ Array
Download sites_urls from response.
54 55 56 57 58 59 60 |
# File 'lib/infosimples/data/client.rb', line 54 def download_sites_urls(response) return [] if !response.is_a?(Hash) || (sites_urls = response.dig('receipt', 'sites_urls')).nil? sites_urls.map do |url| Infosimples::Data::HTTP.request(url: url, http_timeout: 30) end end |
#pricing ⇒ Array
Get prices for each service.
45 46 47 |
# File 'lib/infosimples/data/client.rb', line 45 def pricing request('pricing', :get) end |