Sha256: 0a69cd4fce747ff407cffc16808c8d358b8d3b5935ea5cd33169db51926fb969

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

require 'httparty'

module Channable
  class Client
    include ::HTTParty

    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

    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

    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

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

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

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

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_channable-0.0.24 lib/channable/client.rb
spree_channable-0.0.23 lib/channable/client.rb
spree_channable-0.0.22 lib/channable/client.rb
spree_channable-0.0.21 lib/channable/client.rb
spree_channable-0.0.20 lib/channable/client.rb
spree_channable-0.0.18.alpha lib/channable/client.rb