Class: StraightServerKit::Client
- Inherits:
-
Object
- Object
- StraightServerKit::Client
- Defined in:
- lib/straight-server-kit/client.rb
Defined Under Namespace
Classes: SigningMiddleware
Constant Summary collapse
- DEFAULT_API_URL =
'http://localhost:9000'.freeze
Instance Attribute Summary collapse
-
#gateway_id ⇒ Object
readonly
Returns the value of attribute gateway_id.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(gateway_id:, secret:, url: DEFAULT_API_URL) ⇒ Client
constructor
A new instance of Client.
- #method_missing(name, *args, &block) ⇒ Object
- #pay_url(order) ⇒ Object
Constructor Details
#initialize(gateway_id:, secret:, url: DEFAULT_API_URL) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 |
# File 'lib/straight-server-kit/client.rb', line 10 def initialize(gateway_id:, secret:, url: DEFAULT_API_URL) @gateway_id = gateway_id @secret = secret @url = url @resources = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/straight-server-kit/client.rb', line 28 def method_missing(name, *args, &block) if self.class.resources.has_key?(name) resources[name] ||= self.class.resources[name].for_gateway(@gateway_id).new(connection: connection) else super end end |
Instance Attribute Details
#gateway_id ⇒ Object (readonly)
Returns the value of attribute gateway_id.
8 9 10 |
# File 'lib/straight-server-kit/client.rb', line 8 def gateway_id @gateway_id end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
8 9 10 |
# File 'lib/straight-server-kit/client.rb', line 8 def resources @resources end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
8 9 10 |
# File 'lib/straight-server-kit/client.rb', line 8 def secret @secret end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/straight-server-kit/client.rb', line 8 def url @url end |
Class Method Details
.resources ⇒ Object
36 37 38 39 40 |
# File 'lib/straight-server-kit/client.rb', line 36 def self.resources { orders: OrderResource, } end |
Instance Method Details
#connection ⇒ Object
21 22 23 24 25 26 |
# File 'lib/straight-server-kit/client.rb', line 21 def connection Faraday.new() do |faraday| faraday.use SigningMiddleware, @secret faraday.adapter :net_http end end |
#pay_url(order) ⇒ Object
17 18 19 |
# File 'lib/straight-server-kit/client.rb', line 17 def pay_url(order) File.join(url, order.pay_path) if order.pay_path end |