Class: Omise::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/omise/resource.rb

Constant Summary collapse

DEFAULT_HEADERS =
{
  user_agent: "OmiseRuby/#{Omise::VERSION} Ruby/#{RUBY_VERSION}",
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, path, key) ⇒ Resource

Returns a new instance of Resource.



14
15
16
17
18
19
20
# File 'lib/omise/resource.rb', line 14

def initialize(url, path, key)
  @uri     = prepare_uri(url, path)
  @headers = prepare_headers
  @key     = key

  set_resource
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



22
23
24
# File 'lib/omise/resource.rb', line 22

def headers
  @headers
end

#keyObject (readonly)

Returns the value of attribute key.



22
23
24
# File 'lib/omise/resource.rb', line 22

def key
  @key
end

#uriObject (readonly)

Returns the value of attribute uri.



22
23
24
# File 'lib/omise/resource.rb', line 22

def uri
  @uri
end

Instance Method Details

#deleteObject



50
51
52
53
54
55
# File 'lib/omise/resource.rb', line 50

def delete
  @resource.delete do |response, request|
    log(request, response)
    Omise::Util.load_response(response)
  end
end

#get(attributes = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/omise/resource.rb', line 24

def get(attributes = {})
  if attributes.any?
    @uri.query = Omise::Util.generate_query(attributes)
    set_resource
  end

  @resource.get do |response, request|
    log(request, response)
    Omise::Util.load_response(response)
  end
end

#patch(attributes = {}) ⇒ Object



36
37
38
39
40
41
# File 'lib/omise/resource.rb', line 36

def patch(attributes = {})
  @resource.patch(attributes) do |response, request|
    log(request, response)
    Omise::Util.load_response(response)
  end
end

#post(attributes = {}) ⇒ Object



43
44
45
46
47
48
# File 'lib/omise/resource.rb', line 43

def post(attributes = {})
  @resource.post(attributes) do |response, request|
    log(request, response)
    Omise::Util.load_response(response)
  end
end