Class: Filter8::Client
- Inherits:
-
Object
- Object
- Filter8::Client
- Defined in:
- lib/filter8/client.rb
Constant Summary collapse
- API_URL =
'https://api.filter8.com'
- API_ENDPOINT =
'/content/item.js'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
Instance Method Summary collapse
-
#initialize(api_key: nil, api_secret: nil, options: {}) ⇒ Client
constructor
A new instance of Client.
- #nonce_param ⇒ Object
- #password ⇒ Object
- #send_request(filter8_request) ⇒ Object
- #timestamp ⇒ Object
Constructor Details
#initialize(api_key: nil, api_secret: nil, options: {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 |
# File 'lib/filter8/client.rb', line 13 def initialize(api_key: nil, api_secret: nil, options: {}) @api_key = api_key @api_secret = api_secret @options = end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/filter8/client.rb', line 8 def api_key @api_key end |
#api_secret ⇒ Object
Returns the value of attribute api_secret.
8 9 10 |
# File 'lib/filter8/client.rb', line 8 def api_secret @api_secret end |
Instance Method Details
#nonce_param ⇒ Object
33 34 35 |
# File 'lib/filter8/client.rb', line 33 def nonce_param "nonce=#{}" end |
#password ⇒ Object
37 38 39 |
# File 'lib/filter8/client.rb', line 37 def password Digest::MD5.hexdigest("#{}#{self.api_secret}") end |
#send_request(filter8_request) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/filter8/client.rb', line 19 def send_request(filter8_request) conn = Faraday.new(:url => API_URL) do |faraday| faraday.request :url_encoded faraday.adapter Faraday.default_adapter end conn.basic_auth self.api_key, password response = conn.post "#{API_ENDPOINT}?#{nonce_param}", filter8_request.request_params raise Exception.new("Filter8-API error (Status: #{response.status}): #{response.body}") if(response.status != 200) Filter8::Result.new JSON.parse(response.body) end |
#timestamp ⇒ Object
41 42 43 |
# File 'lib/filter8/client.rb', line 41 def @timestamp ||= Time.now.to_i.to_s end |