Class: TapClutch::Client
- Inherits:
-
Struct
- Object
- Struct
- TapClutch::Client
- Defined in:
- lib/client.rb
Overview
rubocop:disable Metrics/BlockLength
Instance Method Summary collapse
- #build_faraday ⇒ Object
- #faraday ⇒ Object
-
#initialize(**kwargs) ⇒ Client
constructor
A new instance of Client.
- #output(hash) ⇒ Object
- #process(start_date = '2018-01-11') ⇒ Object
Constructor Details
#initialize(**kwargs) ⇒ Client
Returns a new instance of Client.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/client.rb', line 28 def initialize(**kwargs) super(*members.map { |k| kwargs[k] }) Clutch.configure do |c| c.clutch_api_key = api_key c.clutch_api_secret = api_secret c.clutch_api_base = api_base c.clutch_brand = brand c.clutch_location = location c.clutch_terminal = terminal end end |
Instance Method Details
#build_faraday ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/client.rb', line 46 def build_faraday # TODO: Extract clutch portal URL to config.json Faraday.new(url: 'https://portal.clutch.com') do |builder| builder.use :cookie_jar builder.request :url_encoded builder.response :json builder.adapter Faraday.default_adapter end end |
#faraday ⇒ Object
40 41 42 43 44 |
# File 'lib/client.rb', line 40 def faraday @faraday ||= build_faraday.tap do |f| f.post '/authenticate/userpass', username: username, password: password end end |
#output(hash) ⇒ Object
63 64 65 |
# File 'lib/client.rb', line 63 def output(hash) stream.puts JSON.generate(hash) end |
#process(start_date = '2018-01-11') ⇒ Object
56 57 58 59 60 61 |
# File 'lib/client.rb', line 56 def process(start_date = '2018-01-11') start_date = Date.parse(start_date) if start_date.is_a? String (start_date..Time.current.getlocal.to_date).each do |date| process_date date end end |