Class: Balanced::Client
- Inherits:
-
Object
- Object
- Balanced::Client
- Defined in:
- lib/balanced_ach/client.rb
Constant Summary collapse
- DEFAULTS =
{ :scheme => 'http', :host => 'localhost', :port => 5000, :version => 'v1', :logging_level => 'WARN', :connection_timeout => 2, :read_timeout => 5, :logger => nil }
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#config ⇒ Object
Returns the value of attribute config.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Instance Method Summary collapse
- #build_conn ⇒ Object
-
#initialize(api_key, options = {}) ⇒ Client
constructor
A new instance of Client.
-
#url ⇒ Object
end.
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
71 72 73 74 75 76 77 78 79 |
# File 'lib/balanced_ach/client.rb', line 71 def method_missing(method, *args, &block) case method when :get, :post, :put, :delete conn.basic_auth(api_key, '') unless api_key.nil? conn.send method, *args else super end end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
23 24 25 |
# File 'lib/balanced_ach/client.rb', line 23 def api_key @api_key end |
#config ⇒ Object
Returns the value of attribute config.
23 24 25 |
# File 'lib/balanced_ach/client.rb', line 23 def config @config end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
22 23 24 |
# File 'lib/balanced_ach/client.rb', line 22 def conn @conn end |
Instance Method Details
#build_conn ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/balanced_ach/client.rb', line 31 def build_conn if config[:logger] logger = config[:logger] else logger = Logger.new(STDOUT) logger.level = Logger.const_get(config[:logging_level].to_s) end Faraday.register_middleware :response, :handle_balanced_errors => lambda {Faraday::Response::RaiseBalancedError} = { :request => { :open_timeout => config[:connection_timeout], :timeout => config[:read_timeout] } } @conn = Faraday.new(url, ) do |cxn| cxn.request :json cxn.response :logger, logger cxn.response :handle_balanced_errors cxn.response :json # cxn.response :raise_error # raise exceptions on 40x, 50x responses cxn.adapter Faraday.default_adapter end conn.path_prefix = '/' conn.headers['User-Agent'] = "balanced-ach-ruby/#{Balanced::VERSION}" end |
#url ⇒ Object
end
65 66 67 |
# File 'lib/balanced_ach/client.rb', line 65 def url URI::HTTPS.build :host => config[:host], :port => config[:port] end |