Class: SelfPay::Client
- Inherits:
-
Object
- Object
- SelfPay::Client
- Includes:
- HTTParty
- Defined in:
- lib/SelfPay/client.rb
Direct Known Subclasses
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
- #delete(path) ⇒ Object
- #get(path) ⇒ Object
- #host ⇒ Object
-
#initialize(env = :sandbox, auth = nil, opts = {}) ⇒ Client
constructor
A new instance of Client.
- #opts ⇒ Object
- #post(path, resource, content_type = "application/json") ⇒ Object
- #production? ⇒ Boolean
- #put(path, resource) ⇒ Object
- #sandbox? ⇒ Boolean
Constructor Details
#initialize(env = :sandbox, auth = nil, opts = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 |
# File 'lib/SelfPay/client.rb', line 7 def initialize(env = :sandbox, auth = nil, opts = {}) @env = env.to_sym @auth = auth @opts = opts @uri = get_base_uri self.class.base_uri @uri end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
5 6 7 |
# File 'lib/SelfPay/client.rb', line 5 def auth @auth end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
5 6 7 |
# File 'lib/SelfPay/client.rb', line 5 def env @env end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
5 6 7 |
# File 'lib/SelfPay/client.rb', line 5 def uri @uri end |
Instance Method Details
#delete(path) ⇒ Object
54 55 56 57 58 |
# File 'lib/SelfPay/client.rb', line 54 def delete(path) resp = self.class.delete path, opts create_response resp end |
#get(path) ⇒ Object
60 61 62 63 64 |
# File 'lib/SelfPay/client.rb', line 60 def get(path) resp = self.class.get path, opts create_response resp end |
#host ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/SelfPay/client.rb', line 66 def host if production? "cliente.hysoft.com.br/Services/Ecommerce/v2" else "cliente.hysoft.com.br/Sandbox/Ecommerce/v2" end end |
#opts ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/SelfPay/client.rb', line 24 def opts opts = @opts opts[:headers] ||= {} opts[:headers].merge!( "Content-Type" => "application/json", "Authorization" => auth.header, "User-Agent" => "#{SelfPay::VERSION}", ) opts end |
#post(path, resource, content_type = "application/json") ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/SelfPay/client.rb', line 37 def post(path, resource, content_type = "application/json") new_opts = opts new_opts[:headers]["Content-Type"] = content_type = new_opts.merge(body: encode_resource(content_type, resource)) #resp = self.class.post path, options #create_response resp return end |
#production? ⇒ Boolean
20 21 22 |
# File 'lib/SelfPay/client.rb', line 20 def production? env == :production end |
#put(path, resource) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/SelfPay/client.rb', line 47 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
16 17 18 |
# File 'lib/SelfPay/client.rb', line 16 def sandbox? env == :sandbox end |