Class: Clutch::Client
- Inherits:
-
Object
- Object
- Clutch::Client
- Defined in:
- lib/clutch/client.rb
Defined Under Namespace
Modules: NeverCapitalize
Constant Summary collapse
- HEADER_KEYS =
%w[brand location terminal].map{ |key| key.extend(NeverCapitalize) }
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #build_connection ⇒ Object
- #headers ⇒ Object
-
#initialize(connection = nil) ⇒ Client
constructor
A new instance of Client.
- #post(path, hash) ⇒ Object
Constructor Details
#initialize(connection = nil) ⇒ Client
Returns a new instance of Client.
24 25 26 |
# File 'lib/clutch/client.rb', line 24 def initialize(connection = nil) @connection = connection || build_connection end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
11 12 13 |
# File 'lib/clutch/client.rb', line 11 def connection @connection end |
Instance Method Details
#build_connection ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/clutch/client.rb', line 28 def build_connection #opts = { ssl: { verify: false }, proxy: "http://localhost:8888" } opts = {} Faraday.new(api_base, opts) do |faraday| faraday.request :json faraday.response :mashify faraday.response :json faraday.adapter :net_http end.tap do |faraday| faraday.basic_auth api_key, api_secret end end |
#headers ⇒ Object
20 21 22 |
# File 'lib/clutch/client.rb', line 20 def headers Hash[HEADER_KEYS.map{ |key| [key, send(key) ] }] end |
#post(path, hash) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/clutch/client.rb', line 42 def post(path, hash) response = connection.post(path, JSON.generate(hash)) do |conn| conn.headers.merge!(headers) end response.body end |