Class: Channable::Client

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

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/channable/client.rb', line 7

def initialize
  self.class.base_uri "https://api.channable.com/v1/companies/#{SpreeChannable.configuration.company_id}/projects/#{SpreeChannable.configuration.project_id}"
  self.class.headers 'Authorization' => "Bearer #{SpreeChannable.configuration.channable_api_key}"
  self.class.headers 'Content-Type' => 'application/json'
end

Instance Method Details

#cancellation_update(order_id) ⇒ Object



37
38
39
# File 'lib/channable/client.rb', line 37

def cancellation_update(order_id)
  Channable::Response.new(self.class.post("/orders/#{order_id}/cancel"))
end

#get_orders(start_date: 1.day.ago, offset: 0, limit: 100) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/channable/client.rb', line 13

def get_orders(start_date: 1.day.ago, offset: 0, limit: 100)
  Channable::Response.new(self.class.get('/orders', query: {
      limit: limit,
      start_date: start_date.strftime('%Y-%m-%d'),
      offset: offset
  }))
end

#get_returns(start_date: 1.day.ago, offset: 0, limit: 100) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/channable/client.rb', line 21

def get_returns(start_date: 1.day.ago, offset: 0, limit: 100)
  Channable::Response.new(self.class.get('/returns', query: {
      limit: limit,
      start_date: start_date,
      offset: offset
  }))
end

#return_update(return_id, return_body) ⇒ Object



29
30
31
# File 'lib/channable/client.rb', line 29

def return_update(return_id, return_body)
  Channable::Response.new(self.class.post("/returns/#{return_id}/status", body: return_body))
end

#shipment_update(order_id, shipment_body) ⇒ Object



33
34
35
# File 'lib/channable/client.rb', line 33

def shipment_update(order_id, shipment_body)
  Channable::Response.new(self.class.post("/orders/#{order_id}/shipment", body: shipment_body))
end