Class: Custplace::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/custplace/base.rb

Direct Known Subclasses

Reviews, Stores

Constant Summary collapse

API_VERSION =
'3.1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Custplace::Api::Base

Initialize a new Custplace::Api::Base

Parameters:



16
17
18
# File 'lib/custplace/base.rb', line 16

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



10
11
12
# File 'lib/custplace/base.rb', line 10

def client
  @client
end

Instance Method Details

#default_headersObject



20
21
22
23
24
25
# File 'lib/custplace/base.rb', line 20

def default_headers
  {
    "Custplace-Version": API_VERSION,
    "Authorization": "Bearer #{client.access_token}"
  }
end

#get(path, params: {}) ⇒ Object



27
28
29
30
31
# File 'lib/custplace/base.rb', line 27

def get(path, params: {})
  response = self.class.get("#{}#{path}", query: params, headers: default_headers)
  parsed_response = response.parsed_response
  parsed_response
end

#post(path, params: {}) ⇒ Object



33
34
35
36
37
# File 'lib/custplace/base.rb', line 33

def post(path, params: {})
  response = self.class.post("#{}#{path}", body: params.to_json, headers: default_headers)
  parsed_response = response.parsed_response
  parsed_response
end