Class: SelfPay::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/SelfPay/client.rb

Direct Known Subclasses

ConnectClient

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#authObject (readonly)

Returns the value of attribute auth.



5
6
7
# File 'lib/SelfPay/client.rb', line 5

def auth
  @auth
end

#envObject (readonly)

Returns the value of attribute env.



5
6
7
# File 'lib/SelfPay/client.rb', line 5

def env
  @env
end

#uriObject (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

#hostObject



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

#optsObject



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
  options = new_opts.merge(body: encode_resource(content_type, resource))

  #resp = self.class.post path, options
  #create_response resp
  return options
end

#production?Boolean

Returns:

  • (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)
  options = opts.merge(body: convert_hash_keys_to(:camel_case, resource).to_json)
  resp = self.class.put path, options

  create_response resp
end

#sandbox?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/SelfPay/client.rb', line 16

def sandbox?
  env == :sandbox
end