Module: Spree::Conekta::Client

Included in:
CreditCard, CreditCardCollection, Customer, Provider
Defined in:
lib/spree/conekta/client.rb

Constant Summary collapse

CONEKTA_API =
'https://api.conekta.io/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



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

def auth_token
  @auth_token
end

Instance Method Details

#connectionObject



15
16
17
18
19
20
21
22
23
# File 'lib/spree/conekta/client.rb', line 15

def connection
  Faraday.new(url: CONEKTA_API) do |faraday|
    faraday.request :url_encoded

    faraday.headers = headers
    faraday.adapter :typhoeus
    faraday.basic_auth(auth_token, nil)
  end
end

#endpointObject



32
33
34
# File 'lib/spree/conekta/client.rb', line 32

def endpoint
  raise 'Not Implemented'
end

#getObject



11
12
13
# File 'lib/spree/conekta/client.rb', line 11

def get
  Oj.load connection.get(endpoint).body
end

#headersObject



25
26
27
28
29
30
# File 'lib/spree/conekta/client.rb', line 25

def headers
  {
    'Accept' => ' application/vnd.conekta-v0.3.0+json',
    'Content-type' => ' application/json'
  }
end

#post(params) ⇒ Object



7
8
9
# File 'lib/spree/conekta/client.rb', line 7

def post(params)
  Oj.load connection.post(endpoint, Oj.dump(params)).body
end