Class: Slice::Client

Inherits:
Object
  • Object
show all
Includes:
ResourceBasedMethods
Defined in:
lib/slice/client.rb

Constant Summary collapse

DEFAULT_ACCEPT =
"application/json"
DEFAULT_HOST =
"api.slice.com"
DEFAULT_USER_AGENT =
"Slice Ruby Gem #{Slice::VERSION}"
DEFAULT_HEADERS =
{
  "Accept" => DEFAULT_ACCEPT,
  "User-Agent" => DEFAULT_USER_AGENT,
}

Instance Method Summary collapse

Methods included from ResourceBasedMethods

#create_item, #create_order, #create_shipment, #delete_item, #delete_order, #delete_shipment, #get_email, #get_email_content, #get_item, #get_mailbox, #get_merchant, #get_order, #get_recall, #get_shipment, #list_categories, #list_items, #list_mailboxes, #list_orders, #list_providers, #list_purchasetypes, #list_recalls, #list_shipments, #list_shippers, #update, #update_item, #update_order, #update_shipment, #whoami

Constructor Details

#initialize(access_token: nil, host: nil, ssl: true) ⇒ Client

### Slice::Client.new(options = {}) Creates a new instance of Slice::Client class. options can have following key-values:

  • access_token - (String) Access token issued to authenticate and authorize user.

  • host - (String) Hostname where this client accesses to.

“‘rb Slice::Client.new Slice::Client.new(access_token: “…”) “`



35
36
37
38
39
# File 'lib/slice/client.rb', line 35

def initialize(access_token: nil, host: nil, ssl: true)
  @access_token = access_token
  @host = host
  @ssl = ssl
end

Instance Method Details

#connectionObject

### Slice::Client#connection Returns a Faraday::Connection to customize by your favorite middlewares.

“‘rb client.connection.response :logger “`



108
109
110
111
112
113
114
# File 'lib/slice/client.rb', line 108

def connection
  @connection ||= Faraday.new(faraday_client_options) do |connection|
    connection.request :json
    connection.response :json
    connection.adapter Faraday.default_adapter
  end
end

#delete(path, params = nil, headers = nil) ⇒ Object

### Slice::Client#delete(path, params = nil, headers = nil) Sends DELETE request, then returns a Slice::Response. params are url-encoded and used as URI query string.

“‘rb client.delete(“/api/v1/items/123”) “`



97
98
99
# File 'lib/slice/client.rb', line 97

def delete(path, params = nil, headers = nil)
  process(:delete, path, params, headers)
end

#get(path, params = nil, headers = nil) ⇒ Object

### Slice::Client#get(path, params = nil, headers = nil) Sends GET request with given parameters, then returns a Slice::Response. params are url-encoded and used as URI query string.

“‘rb client.get(“/api/v1/items”, page: 2) “`



49
50
51
# File 'lib/slice/client.rb', line 49

def get(path, params = nil, headers = nil)
  process(:get, path, params, headers)
end

#patch(path, params = nil, headers = nil) ⇒ Object

### Slice::Client#patch(path, params = nil, headers = nil) Sends PATCH request with given parameters, then returns a Slice::Response. params are JSON-encoded and used as request body.

“‘rb client.patch(“/api/v1/items/123”, title: “…”, body: “…”) “`



73
74
75
# File 'lib/slice/client.rb', line 73

def patch(path, params = nil, headers = nil)
  process(:patch, path, params, headers)
end

#post(path, params = nil, headers = nil) ⇒ Object

### Slice::Client#post(path, params = nil, headers = nil) Sends POST request with given parameters, then returns a Slice::Response. params are JSON-encoded and used as request body.

“‘rb client.post(“/api/v1/items”, category: “…”, price: “…”) “`



61
62
63
# File 'lib/slice/client.rb', line 61

def post(path, params = nil, headers = nil)
  process(:post, path, params, headers)
end

#put(path, params = nil, headers = nil) ⇒ Object

### Slice::Client#put(path, params = nil, headers = nil) Sends PUT request, then returns a Slice::Response. params are JSON-encoded and used as request body.

“‘rb client.put(“/api/v1/items/123”) “`



85
86
87
# File 'lib/slice/client.rb', line 85

def put(path, params = nil, headers = nil)
  process(:put, path, params, headers)
end