Class: Moip2::Client
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #get(path) ⇒ Object
-
#initialize(env = :sandbox, auth = nil, opts = {}) ⇒ Client
constructor
A new instance of Client.
- #opts ⇒ Object
- #post(path, resource) ⇒ Object
- #production? ⇒ Boolean
- #put(path, resource) ⇒ Object
- #sandbox? ⇒ Boolean
Constructor Details
#initialize(env = :sandbox, auth = nil, opts = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 |
# File 'lib/moip2/client.rb', line 8 def initialize(env = :sandbox, auth = nil, opts = {}) @env, @auth, @opts = env.to_sym, auth, opts @uri = get_base_uri self.class.base_uri @uri end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
6 7 8 |
# File 'lib/moip2/client.rb', line 6 def auth @auth end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/moip2/client.rb', line 6 def env @env end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
6 7 8 |
# File 'lib/moip2/client.rb', line 6 def uri @uri end |
Instance Method Details
#get(path) ⇒ Object
50 51 52 53 54 |
# File 'lib/moip2/client.rb', line 50 def get(path) resp = self.class.get path, opts() create_response resp end |
#opts ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/moip2/client.rb', line 23 def opts opts = @opts opts[:headers] ||= {} opts[:headers].merge!( { "Content-Type" => "application/json", "Authorization" => auth.header } ) opts end |
#post(path, resource) ⇒ Object
37 38 39 40 41 |
# File 'lib/moip2/client.rb', line 37 def post(path, resource) = opts().merge(body: convert_hash_keys_to(:camel_case, resource).to_json) resp = self.class.post path, create_response resp end |
#production? ⇒ Boolean
19 20 21 |
# File 'lib/moip2/client.rb', line 19 def production? env == :production end |
#put(path, resource) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/moip2/client.rb', line 43 def put(path, resource) = opts().merge(body: convert_hash_keys_to(:camel_case, resource).to_json) resp = self.class.put path, create_response resp end |
#sandbox? ⇒ Boolean
15 16 17 |
# File 'lib/moip2/client.rb', line 15 def sandbox? env == :sandbox end |