voxbone-ruby 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe08e01083e7a6fe667dc820b5d8f35059d74ce5
4
- data.tar.gz: f8f4e1d57a3610ccd10207f2b5d03b5e43bb5574
3
+ metadata.gz: 14a29040198f11bc7b96bb55c38ed1f6f6d9b818
4
+ data.tar.gz: 5869c09e96d639b9d54419d2888b83f7d55f8cc2
5
5
  SHA512:
6
- metadata.gz: 7cce10925e258517cc299633a41436ddf6b57feee641ecc40c00682fd213a8af1526ce9df12c4fce7af4b46585d44508ec9eee7d2a505753e6c130657e9a68a9
7
- data.tar.gz: fda26751c9ea902abccbbd6f2d2c0765a7e2a583cb35afc6b70f8533ec64b12042140349297b4898b85e13ab0422de279769bde72d26c14f8c9535a60de09459
6
+ metadata.gz: 769e012705cc260fa8fdcfc75c97ed501ed09d4a70e01027726bf4bf1c40d73ea169721ddc5386a022c3b537df79021cb68916bdc3e9c322f2fdde33dae0270b
7
+ data.tar.gz: cedb10e70649e2850c5023d17f3f29563ee53f6274a16cf4a29847a87eaf89b85dbc7fb7a11529065e745c62b89e7d5a466490fcd58161424716e0d6c5e8c15e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- voxbone-ruby (0.0.1)
4
+ voxbone-ruby (0.0.2)
5
5
  httparty
6
6
 
7
7
  GEM
data/lib/voxbone.rb CHANGED
@@ -3,3 +3,4 @@ require 'voxbone/version'
3
3
  require 'voxbone/config'
4
4
 
5
5
  require 'voxbone/inventory'
6
+ require 'voxbone/ordering'
@@ -51,7 +51,7 @@ module Voxbone
51
51
  # that you can specify multiple features by
52
52
  # repeating the query parameter.
53
53
  def list_did_group(**options)
54
- get('/inventory/didgroup', options)
54
+ send_get('/inventory/didgroup', options)
55
55
  end
56
56
  end
57
57
 
@@ -0,0 +1,78 @@
1
+ module Voxbone
2
+ module Ordering
3
+ # Create Cart
4
+ #
5
+ # `create_cart` is a method that allows you to create a cart. Note: The
6
+ # creation of a cart depends on your own business logic, but you'll always
7
+ # need to create at least one cart to place an order (`checkout_cart`). You
8
+ # can place multiple orders per cart or you can create separate carts for
9
+ # each order. Note that different product types (DID, Capacity or prepaid
10
+ # credits) can be added into a single cart.
11
+ #
12
+ # options - Type: Hash. Parameters used to create the cart.
13
+ # customer_reference - A parameter that can be used for your own
14
+ # reference.
15
+ # description - The description or name you want to give
16
+ # the cart.
17
+ def create_cart(**options)
18
+ send_put '/ordering/cart', **options
19
+ end
20
+
21
+ # Add to Cart
22
+ #
23
+ # `add_to_cart` allows you to add items (order_products) to a specific cart
24
+ # before checking out the cart. Different product types (DID, CAPACITY or
25
+ # CREDIT_PACKAGE) can be added into one single cart.
26
+ #
27
+ # Parameters:
28
+ #
29
+ # options - Type: Hash. Parameters used to add an item to a cart.
30
+ # - :cart_identifier - Type: String. Identifies the cart and is returned
31
+ # by the createCart method or can be retrieved with the list_cart
32
+ # method. (Required)
33
+ # - :did_cart_item - Type: Hash. Corresponds to DIDs (VoxDID or Vox800).
34
+ # Note that you can specify multiple DID groups by repeating the query
35
+ # parameter.
36
+ # - :did_group_ids - Type: Integer (multiple). To add one or multiple
37
+ # DIDs to your cart, you need to specify a valid ID for the DID group
38
+ # of the DIDs.
39
+ # - :quantity - Type: Integer. Amount of DIDs from that DID group.
40
+ # - :capacity_cart_item - Type: Hash. Corresponds to capacity (VoxTRUNK
41
+ # channels).
42
+ # - :zone - To add channels to your cart, you need to specify a valid
43
+ # zone (A, B, C or WORLDWIDE). Only one capacity_cart_item can be
44
+ # added per request and capacity must be ordered in multiple of 10.
45
+ # - :quantity - Amount of channels required.
46
+ # - :credit_package_cart_item - Type: Hash. Corresponds to prepaid
47
+ # credits.
48
+ # - :credit_package_id - Type: String. To add prepaid credits to your
49
+ # cart, you need to specify a valid ID for the credit_package
50
+ # - :quantity - Type: Integer. The amount of prepaid credits required.
51
+ def add_to_cart(**options)
52
+ cart_id = options.delete(:cart_id)
53
+ send_post "/ordering/cart/#{cart_id}/product", **options
54
+ end
55
+
56
+ # Checkout Cart
57
+ #
58
+ # `checkout_cart` allows you to checkout a cart and place an order for all
59
+ # the products contained in the cart. You can then retrieve your orders
60
+ # using the list_order method.
61
+ #
62
+ # Parameters:
63
+ # options - Type: Hash. Parameters used to checkout a cart.
64
+ # - :cart_identifier - The identifier of your cart which is formed of a
65
+ # fixed string such as “apiv3:60677:” and an ID which is incremented
66
+ # each time a new cart is created.
67
+ def checkout_cart(**options)
68
+ # For some reason the API docs indicate that "cartIdentifier" should be
69
+ # given as a dynamic segment AND a query string.
70
+ cart_id = options.delete(:cart_id)
71
+ send_get(
72
+ "/ordering/cart/#{cart_id}/checkout",
73
+ **options, cart_identifier: cart_id)
74
+ end
75
+ end
76
+
77
+ extend Ordering
78
+ end
@@ -1,3 +1,3 @@
1
1
  module Voxbone
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'
3
3
  end
@@ -10,15 +10,29 @@ module Voxbone
10
10
  }.freeze
11
11
 
12
12
  class << self
13
- def get(path, **options)
13
+ def send_get(path, **options)
14
+ query = camelize_keys(options) if options
15
+ get(
16
+ path, query: query, headers: HEADERS, basic_auth: auth)
17
+ end
18
+
19
+ def send_put(path, **options)
14
20
  auth = { username: username, password: password }
15
21
  query = camelize_keys(options) if options
16
- super(
22
+ put(
23
+ path, query: query, headers: HEADERS, basic_auth: auth)
24
+ end
25
+
26
+ def send_post(path, **options)
27
+ auth = { username: username, password: password }
28
+ query = camelize_keys(options)
29
+ post(
17
30
  path, query: query, headers: HEADERS, basic_auth: auth)
18
31
  end
19
32
 
20
- def camelize_keys(hash)
21
- Hash[hash.map { |key, value| [camelize(key), value] }]
33
+ def camelize_keys(obj)
34
+ return obj unless obj.is_a?(Hash)
35
+ Hash[obj.map { |key, value| [camelize(key), camelize_keys(value)] }]
22
36
  end
23
37
 
24
38
  def camelize(string)
@@ -26,5 +40,9 @@ module Voxbone
26
40
  transformed_parts = parts[1..-1].map(&:capitalize).unshift(parts[0])
27
41
  transformed_parts.join
28
42
  end
43
+
44
+ def auth
45
+ { username: username, password: password }
46
+ end
29
47
  end
30
48
  end
@@ -5,8 +5,15 @@ describe Voxbone::Inventory do
5
5
  it 'correctly makes the request' do
6
6
  expect(Voxbone).to receive(:get).with(
7
7
  '/inventory/didgroup',
8
- country_code_a3: 'USA', page_number: 0, page_size: 5, area_code: '225')
9
-
8
+ query: {
9
+ 'countryCodeA3' => 'USA',
10
+ 'pageNumber' => 0,
11
+ 'pageSize' => 5,
12
+ 'areaCode' => '225'
13
+ },
14
+ headers: Voxbone::HEADERS,
15
+ basic_auth: Voxbone.auth
16
+ )
10
17
  Voxbone.list_did_group(
11
18
  country_code_a3: 'USA', page_number: 0, page_size: 5, area_code: '225')
12
19
  end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Voxbone::Ordering do
4
+ describe '#create_cart' do
5
+ it 'correctly makes the request' do
6
+ expect(Voxbone).to receive(:put).with(
7
+ '/ordering/cart',
8
+ query: { 'customerReference' => 'me', 'description' => 'my_cart' },
9
+ headers: Voxbone::HEADERS,
10
+ basic_auth: Voxbone.auth
11
+ )
12
+ Voxbone.create_cart(
13
+ customer_reference: 'me', description: 'my_cart'
14
+ )
15
+ end
16
+ end
17
+
18
+ describe '#add_to_cart' do
19
+ it 'correctly makes the request' do
20
+ expect(Voxbone).to receive(:post).with(
21
+ '/ordering/cart/1234/product',
22
+ query: {
23
+ 'didCartItem' => {
24
+ 'didGroupIds' => 1,
25
+ 'quantity' => 1
26
+ }
27
+ },
28
+ headers: Voxbone::HEADERS,
29
+ basic_auth: Voxbone.auth
30
+ )
31
+ Voxbone.add_to_cart(
32
+ cart_id: '1234',
33
+ did_cart_item: {
34
+ did_group_ids: 1,
35
+ quantity: 1
36
+ }
37
+ )
38
+ end
39
+ end
40
+
41
+ describe '#checkout_cart' do
42
+ it 'correctly makes the request' do
43
+ expect(Voxbone).to receive(:get).with(
44
+ '/ordering/cart/1234/checkout',
45
+ query: { 'cartIdentifier' => '1234' },
46
+ headers: Voxbone::HEADERS,
47
+ basic_auth: Voxbone.auth
48
+ )
49
+ Voxbone.checkout_cart(cart_id: '1234')
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voxbone-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Negrotto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-17 00:00:00.000000000 Z
11
+ date: 2016-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -66,10 +66,12 @@ files:
66
66
  - lib/voxbone.rb
67
67
  - lib/voxbone/config.rb
68
68
  - lib/voxbone/inventory.rb
69
+ - lib/voxbone/ordering.rb
69
70
  - lib/voxbone/version.rb
70
71
  - lib/voxbone/voxbone.rb
71
72
  - spec/spec_helper.rb
72
73
  - spec/voxbone/inventory_spec.rb
74
+ - spec/voxbone/ordering_spec.rb
73
75
  - voxbone-ruby.gemspec
74
76
  homepage: ''
75
77
  licenses: []
@@ -97,4 +99,5 @@ summary: A gem for interacting with Voxbone's REST API.
97
99
  test_files:
98
100
  - spec/spec_helper.rb
99
101
  - spec/voxbone/inventory_spec.rb
102
+ - spec/voxbone/ordering_spec.rb
100
103
  has_rdoc: