Class: Prove::Client
- Inherits:
-
Object
- Object
- Prove::Client
- Defined in:
- lib/prove/client.rb
Constant Summary collapse
- DEFAULTS =
{faraday_adapter: Faraday.default_adapter, log_level: :warn, logger: Logger.new(STDOUT), scheme: :https, port: 443, host: 'getprove.com'}
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#connection ⇒ Object
Returns the value of attribute connection.
Instance Method Summary collapse
- #get(url, options = {}, &block) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Client
constructor
A new instance of Client.
- #post(url, options = {}, &block) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/prove/client.rb', line 16 def initialize(={}, &block) config = DEFAULTS.merge() if !.has_key?(:logger) or (.has_key?(:log_level) and .has_key?(:logger)) config[:logger].level = Logger.const_get(config[:log_level].to_s.upcase) end block = block_given? ? block : Proc.new do |cxn| cxn.request :url_encoded cxn.response :logger, config[:logger] cxn.response :json # cxn.response :raise_error # raise exceptions on 40x, 50x responses cxn.adapter config[:faraday_adapter] end url_builder = config[:scheme] == :http ? URI::HTTP : URI::HTTPS url = url_builder.build(host: config[:host], port: config[:port]) @connection = Faraday.new(url, &block) @connection.headers['User-Agent'] = "Prove-Ruby" self.api_key = config[:api_key] end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/prove/client.rb', line 7 def api_key @api_key end |
#connection ⇒ Object
Returns the value of attribute connection.
7 8 9 |
# File 'lib/prove/client.rb', line 7 def connection @connection end |
Instance Method Details
#get(url, options = {}, &block) ⇒ Object
46 47 48 |
# File 'lib/prove/client.rb', line 46 def get(url, = {}, &block) return @connection.get(url, , &block) end |
#post(url, options = {}, &block) ⇒ Object
50 51 52 |
# File 'lib/prove/client.rb', line 50 def post(url, = {}, &block) return @connection.post(url, , &block) end |