Class: TapClutch::Client

Inherits:
Struct
  • Object
show all
Defined in:
lib/client.rb

Overview

rubocop:disable Metrics/BlockLength

Instance Method Summary collapse

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_faradayObject



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

#faradayObject



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