Class: Omise::Resource

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

Constant Summary collapse

CA_BUNDLE_PATH =
File.expand_path("../../../data/ca_certificates.pem", __FILE__)
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



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/omise/resource.rb', line 18

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

  @resource = RestClient::Resource.new(@uri, {
    user: key,
    verify_ssl: OpenSSL::SSL::VERIFY_PEER,
    ssl_ca_file: CA_BUNDLE_PATH,
    headers: @headers,
  })
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



31
32
33
# File 'lib/omise/resource.rb', line 31

def headers
  @headers
end

#keyObject (readonly)

Returns the value of attribute key.



31
32
33
# File 'lib/omise/resource.rb', line 31

def key
  @key
end

#uriObject (readonly)

Returns the value of attribute uri.



31
32
33
# File 'lib/omise/resource.rb', line 31

def uri
  @uri
end

Instance Method Details

#deleteObject



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

def delete
  @resource.delete { |r| Omise::Util.load_response(r) }
end

#get(attributes = {}) ⇒ Object



33
34
35
# File 'lib/omise/resource.rb', line 33

def get(attributes = {})
  @resource.get(params: attributes) { |r| Omise::Util.load_response(r) }
end

#patch(attributes = {}) ⇒ Object



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

def patch(attributes = {})
  @resource.patch(attributes) { |r| Omise::Util.load_response(r) }
end

#post(attributes = {}) ⇒ Object



41
42
43
# File 'lib/omise/resource.rb', line 41

def post(attributes = {})
  @resource.post(attributes) { |r| Omise::Util.load_response(r) }
end