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'
- ENCRYPTABLE_ARGS =
['pkcs12_cert', 'pkcs12_pass', 'pass'].map { |arg| [arg, true] }.to_h
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.
22 23 24 25 26 |
# File 'lib/infosimples/data/client.rb', line 22 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.
9 10 11 |
# File 'lib/infosimples/data/client.rb', line 9 def max_age @max_age end |
#timeout ⇒ Object
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/infosimples/data/client.rb', line 9 def timeout @timeout end |
#token ⇒ Object
Returns the value of attribute token.
9 10 11 |
# File 'lib/infosimples/data/client.rb', line 9 def token @token end |
Instance Method Details
#automate(service, args = {}) ⇒ Hash
Automate a service.
34 35 36 37 38 39 40 41 |
# File 'lib/infosimples/data/client.rb', line 34 def automate(service, args = {}) args.keys.each do |key| if ENCRYPTABLE_ARGS[key.to_s] args[key] = encrypt(args[key]) end end request(service, :multipart, args) end |
#billing ⇒ Array
Get billing statistics from your account.
46 47 48 |
# File 'lib/infosimples/data/client.rb', line 46 def billing request('billing', :get) end |
#download_sites_urls(response) ⇒ Array
Download sites_urls from response.
62 63 64 65 66 67 68 |
# File 'lib/infosimples/data/client.rb', line 62 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.
53 54 55 |
# File 'lib/infosimples/data/client.rb', line 53 def pricing request('pricing', :get) end |