Class: StraightServerKit::Client
- Inherits:
-
Object
- Object
- StraightServerKit::Client
- Defined in:
- lib/straight-server-kit/client.rb
Constant Summary collapse
- DEFAULT_API_URL =
'http://localhost:9000'.freeze
Instance Attribute Summary collapse
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(url: DEFAULT_API_URL) ⇒ Client
constructor
A new instance of Client.
- #method_missing(name, *args, &block) ⇒ Object
- #pay_url(order) ⇒ Object
Constructor Details
#initialize(url: DEFAULT_API_URL) ⇒ Client
Returns a new instance of Client.
10 11 12 13 |
# File 'lib/straight-server-kit/client.rb', line 10 def initialize(url: DEFAULT_API_URL) @url = url @resources = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/straight-server-kit/client.rb', line 25 def method_missing(name, *args, &block) if self.class.resources.keys.include?(name) resources[name] ||= self.class.resources[name].new(connection: connection) else super end end |
Instance Attribute Details
#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 |
#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
33 34 35 36 37 |
# File 'lib/straight-server-kit/client.rb', line 33 def self.resources { orders: OrderResource, } end |
Instance Method Details
#connection ⇒ Object
19 20 21 22 23 |
# File 'lib/straight-server-kit/client.rb', line 19 def connection Faraday.new() { |req| req.adapter :net_http } end |
#pay_url(order) ⇒ Object
15 16 17 |
# File 'lib/straight-server-kit/client.rb', line 15 def pay_url(order) File.join(url, order.pay_path) if order.pay_path end |