codes_wholesale 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/codes_wholesale/client.rb +21 -0
- data/lib/codes_wholesale/client/accounts.rb +11 -0
- data/lib/codes_wholesale/client/orders.rb +12 -0
- data/lib/codes_wholesale/client/products.rb +16 -0
- data/lib/codes_wholesale/configurable.rb +17 -0
- data/lib/codes_wholesale/default.rb +22 -0
- data/lib/codes_wholesale/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e2fbc78b949f214b64d39b6e256cc2ddcac7209
|
4
|
+
data.tar.gz: 9ba86498351d849ff36ab3c3886bfaf00e7aa3f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4eb8cd10f39f51306f746595f233cf37852c8d08f2e48c2185eac30afb5722551973e89a719de6f427c705384e6ec1e0db5b06dc6612aac61779726b2c153dc
|
7
|
+
data.tar.gz: 01d4baf587a6309ccf3ef4ed58927f5ddf9eaa5e0b42ccbac5aeeaccd2ac61896c285b5b8cea6b163c90c0b179533ae95b3678f7ce53394eee984bdf5e093211
|
@@ -4,6 +4,10 @@ require 'codes_wholesale/client/products'
|
|
4
4
|
require 'codes_wholesale/client/orders'
|
5
5
|
|
6
6
|
module CodesWholesale
|
7
|
+
|
8
|
+
# Client for the CodesWholesale API
|
9
|
+
#
|
10
|
+
# @see https://docs.codeswholesale.com/api-documentation/
|
7
11
|
class Client
|
8
12
|
include CodesWholesale::Configurable
|
9
13
|
include CodesWholesale::Client::Accounts
|
@@ -11,15 +15,22 @@ module CodesWholesale
|
|
11
15
|
include CodesWholesale::Client::Orders
|
12
16
|
|
13
17
|
def initialize(options = {})
|
18
|
+
# Use options passed in, but fall back to module defaults
|
14
19
|
CodesWholesale::Configurable.keys.each do |key|
|
15
20
|
instance_variable_set(:"@#{key}", options[key] || CodesWholesale.instance_variable_get(:"@#{key}"))
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
24
|
+
# Authenticates and get the token in order to make requests to the API
|
25
|
+
#
|
26
|
+
# @return [OAuth2::AccessToken]
|
19
27
|
def token
|
20
28
|
OAuth2::Client.new(client_id, client_secret, site: "#{api_endpoint}/oauth/token").client_credentials.get_token
|
21
29
|
end
|
22
30
|
|
31
|
+
# The actual client that talks to the CodesWholesale API
|
32
|
+
#
|
33
|
+
# @return [Sawyer::Agent]
|
23
34
|
def agent
|
24
35
|
@agent ||= Sawyer::Agent.new(api_endpoint, sawyer_options) do |http|
|
25
36
|
http.headers[:content_type] = 'application/json'
|
@@ -30,10 +41,20 @@ module CodesWholesale
|
|
30
41
|
end
|
31
42
|
end
|
32
43
|
|
44
|
+
# Make a HTTP GET request
|
45
|
+
#
|
46
|
+
# @param url [String] The path relative to {#api_endpoint}
|
47
|
+
# @param options [Hash] Query and other params for the request
|
48
|
+
# @return [Sawyer::Resource]
|
33
49
|
def get(url, options = {})
|
34
50
|
request(:get, url, options)
|
35
51
|
end
|
36
52
|
|
53
|
+
# Make a HTTP POST request
|
54
|
+
#
|
55
|
+
# @param url [String] The path relative to {#api_endpoint}
|
56
|
+
# @param options [Hash] Query and other params for the request
|
57
|
+
# @return [Sawyer::Resource]
|
37
58
|
def post(url, options = {})
|
38
59
|
request(:post, url, options)
|
39
60
|
end
|
@@ -2,7 +2,18 @@ require 'codes_wholesale/models/account'
|
|
2
2
|
|
3
3
|
module CodesWholesale
|
4
4
|
class Client
|
5
|
+
|
6
|
+
# Methods for the Accounts API
|
7
|
+
#
|
8
|
+
# @see https://docs.codeswholesale.com/api-documentation
|
5
9
|
module Accounts
|
10
|
+
|
11
|
+
# Return the current account details
|
12
|
+
#
|
13
|
+
# @return [CodesWholesale::Models::Account] Account of the authenticated user
|
14
|
+
# @see https://docs.codeswholesale.com/api-documentation/#api-account-details
|
15
|
+
# @example Get current account details
|
16
|
+
# CodesWholesale.account
|
6
17
|
def account
|
7
18
|
CodesWholesale::Models::Account.new(get('accounts/current'))
|
8
19
|
end
|
@@ -2,7 +2,19 @@ require 'codes_wholesale/models/order'
|
|
2
2
|
|
3
3
|
module CodesWholesale
|
4
4
|
class Client
|
5
|
+
|
6
|
+
# Methods for the Orders API
|
7
|
+
#
|
8
|
+
# @see https://docs.codeswholesale.com/api-documentation
|
5
9
|
module Orders
|
10
|
+
|
11
|
+
# Order a product
|
12
|
+
#
|
13
|
+
# @param product_id [String] ID of the product
|
14
|
+
# @return [CodesWholesale::Models::Order] Order details
|
15
|
+
# @see https://docs.codeswholesale.com/api-documentation/#api-single-code
|
16
|
+
# @example Order a product
|
17
|
+
# CodesWholesale.order('6313677f-5219-47e4-a067-7401f55c5a3a')
|
6
18
|
def order(product_id)
|
7
19
|
CodesWholesale::Models::Order.new(post("orders?productId=#{product_id}"))
|
8
20
|
end
|
@@ -2,7 +2,23 @@ require 'codes_wholesale/models/product'
|
|
2
2
|
|
3
3
|
module CodesWholesale
|
4
4
|
class Client
|
5
|
+
|
6
|
+
# Methods for the Products API
|
7
|
+
#
|
8
|
+
# @see https://docs.codeswholesale.com/api-documentation
|
5
9
|
module Products
|
10
|
+
|
11
|
+
# Get all products or get a specific product
|
12
|
+
#
|
13
|
+
# @param id [String] ID of the product
|
14
|
+
# @return [Array<CodesWholesale::Models::Product>] A list of products
|
15
|
+
# @return [CodesWholesale::Models::Product] A product
|
16
|
+
# @see https://docs.codeswholesale.com/api-documentation/#api-products-list
|
17
|
+
# @see https://docs.codeswholesale.com/api-documentation/#api-id-product
|
18
|
+
# @example Get all products
|
19
|
+
# CodesWholesale.products
|
20
|
+
# @example Get a specific product
|
21
|
+
# CodesWholesale.products('6313677f-5219-47e4-a067-7401f55c5a3a')
|
6
22
|
def products(id = nil)
|
7
23
|
if id.nil?
|
8
24
|
products = get('products')
|
@@ -1,9 +1,24 @@
|
|
1
1
|
module CodesWholesale
|
2
|
+
|
3
|
+
# Configuration options for {Client}, defaulting to values in {Default}
|
2
4
|
module Configurable
|
5
|
+
# @!attribute [w] client_id
|
6
|
+
# @return [String] Configure OAuth app key
|
7
|
+
# @!attribute [w] client_secret
|
8
|
+
# @return [String] Configure OAuth app secret
|
9
|
+
# @!attribute [w] environment
|
10
|
+
# @return [String] Configure API environment
|
11
|
+
# @!attribute user_agent
|
12
|
+
# @return [String] Configure User-Agent for requests
|
13
|
+
# @!attribute api_version
|
14
|
+
# @return [String] Configure API version
|
3
15
|
attr_accessor :client_id, :client_secret, :environment,
|
4
16
|
:user_agent, :api_version
|
5
17
|
|
6
18
|
class << self
|
19
|
+
|
20
|
+
# List of configurable keys for {CodesWholesale::Client}
|
21
|
+
# @return [Array] of option keys
|
7
22
|
def keys
|
8
23
|
@keys ||= [
|
9
24
|
:client_id,
|
@@ -15,10 +30,12 @@ module CodesWholesale
|
|
15
30
|
end
|
16
31
|
end
|
17
32
|
|
33
|
+
# Set configuration options through a block
|
18
34
|
def configure
|
19
35
|
yield self
|
20
36
|
end
|
21
37
|
|
38
|
+
# Reset configuration options to default values
|
22
39
|
def reset!
|
23
40
|
CodesWholesale::Configurable.keys.each do |key|
|
24
41
|
instance_variable_set(:"@#{key}", CodesWholesale::Default.options[key])
|
@@ -1,32 +1,54 @@
|
|
1
1
|
require 'codes_wholesale/version'
|
2
2
|
|
3
3
|
module CodesWholesale
|
4
|
+
|
5
|
+
# Default configuration options for {Client}
|
4
6
|
module Default
|
7
|
+
|
8
|
+
# Default API environment
|
5
9
|
ENVIRONMENT = 'production'.freeze
|
10
|
+
|
11
|
+
# Default API version
|
6
12
|
API_VERSION = 'v1'.freeze
|
13
|
+
|
14
|
+
# Default User-Agent header string
|
7
15
|
USER_AGENT = "CodesWholesale Ruby Gem #{CodesWholesale::VERSION}".freeze
|
8
16
|
|
9
17
|
class << self
|
18
|
+
|
19
|
+
# Configuration options
|
20
|
+
# @return [Hash[
|
10
21
|
def options
|
11
22
|
Hash[CodesWholesale::Configurable.keys.map { |key| [key, send(key)] }]
|
12
23
|
end
|
13
24
|
|
25
|
+
# Default API version
|
26
|
+
# @return [String]
|
14
27
|
def api_version
|
15
28
|
ENV['CODES_WHOLESALE_API_VERSION'] ||= API_VERSION
|
16
29
|
end
|
17
30
|
|
31
|
+
# Default API environment
|
32
|
+
# @ return [String]
|
18
33
|
def environment
|
19
34
|
ENV['CODES_WHOLESALE_ENVIRONMENT'] ||= ENVIRONMENT
|
20
35
|
end
|
21
36
|
|
37
|
+
# Default OAuth app key from ENV
|
38
|
+
# @return [String]
|
22
39
|
def client_id
|
23
40
|
ENV['CODES_WHOLESALE_CLIENT_ID']
|
24
41
|
end
|
25
42
|
|
43
|
+
|
44
|
+
# Default OAuth app secret from ENV
|
45
|
+
# @return [String]
|
26
46
|
def client_secret
|
27
47
|
ENV['CODES_WHOLESALE_CLIENT_SECRET']
|
28
48
|
end
|
29
49
|
|
50
|
+
# Default User-Agent header string from ENV or {USER_AGENT}
|
51
|
+
# @return [String]
|
30
52
|
def user_agent
|
31
53
|
ENV['CODES_WHOLESALE_USER_AGENT'] || USER_AGENT
|
32
54
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codes_wholesale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Terence Ponce
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|