Class: Intelipost::Client
- Inherits:
-
Object
- Object
- Intelipost::Client
- Defined in:
- lib/intelipost/client.rb
Constant Summary collapse
- HOST =
'api.intelipost.com.br'
- SERVICE =
'api/'
- API_VERSION =
'v1'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #camelize(term) ⇒ Object
- #get(endpoint, args = {}) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #method_missing(method, *args, &block) ⇒ Object
- #post(endpoint, args = {}) ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/intelipost/client.rb', line 10 def initialize() @options = { ssl: true } @options.merge! uri = @options[:ssl] ? 'https://' : 'http://' uri.concat HOST @uri = URI.join uri, SERVICE, API_VERSION @api_key = @options[:api_key] @platform = @options[:platform] @connection = connection end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/intelipost/client.rb', line 48 def method_missing(method, *args, &block) method = camelize method if Intelipost.const_defined? method return Intelipost.const_get(method).new self else super end end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/intelipost/client.rb', line 8 def api_key @api_key end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
8 9 10 |
# File 'lib/intelipost/client.rb', line 8 def connection @connection end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/intelipost/client.rb', line 8 def @options end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
8 9 10 |
# File 'lib/intelipost/client.rb', line 8 def platform @platform end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
8 9 10 |
# File 'lib/intelipost/client.rb', line 8 def uri @uri end |
Instance Method Details
#camelize(term) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/intelipost/client.rb', line 57 def camelize(term) string = term.to_s string = string.sub(/^[a-z\d]*/) { $&.capitalize } string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" } string.gsub!("/", "::") string end |
#get(endpoint, args = {}) ⇒ Object
40 41 42 |
# File 'lib/intelipost/client.rb', line 40 def get(endpoint, args={}) connection.get(endpoint, args).body end |
#post(endpoint, args = {}) ⇒ Object
44 45 46 |
# File 'lib/intelipost/client.rb', line 44 def post(endpoint, args = {}) connection.post(endpoint, args).body end |