invoiced 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d993a9653fa91682598ce436fd439aac622038b
4
- data.tar.gz: 37fe418a43489d5455477001bd89d11a72a627fb
3
+ metadata.gz: 110fedfb4c7cae791aba433214d0f8d5ce08c322
4
+ data.tar.gz: fc4acd0b415091216c3d83291cbea330cc5f7619
5
5
  SHA512:
6
- metadata.gz: d49663b88444545d104013081d64d7ef34b3a6e7ba631aa5ae33aa7562ebd545266af5d9fe46f0b56b98ddb1d8c8e89be048a80ae06bc0193d1bb89a5f26ac2a
7
- data.tar.gz: a2b40dda8276ca3baeb4f2b0165249980d64fe92f0be2d9d8894738881409c22cae3f5e521b1be8e3ce079a9f7d40fa870e4c53075ad19303be856a92134b4c4
6
+ metadata.gz: ec0bb6d4d38e029afd787bd7e115d27e1c486d1fa13ae4af5f8ee0ff8e87e96fbc9b58bae272decb58c27a9638b88015513ae0a832137be7be3b791fac625a9d
7
+ data.tar.gz: d6ad87477c2c50e44a9df3b7ae3417729d8da78832b97e6d20815d98b9583bacadda9e7cbd694994cbe569762290711c537ac6d7e9f09797989d852e5d0682af
data/README.md CHANGED
@@ -24,7 +24,7 @@ gem 'invoiced'
24
24
 
25
25
  ## Requirements
26
26
 
27
- - >= Ruby 1.9.3
27
+ - Ruby 1.9.3+
28
28
  - rest_client, json, and active_support gems
29
29
 
30
30
  ## Usage
@@ -0,0 +1,8 @@
1
+ module Invoiced
2
+ class CatalogItem < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+ end
8
+ end
@@ -8,7 +8,7 @@ module Invoiced
8
8
  update[k] = @values[k]
9
9
  end
10
10
 
11
- update.merge(params)
11
+ update = update.merge(params)
12
12
 
13
13
  # perform the update if there are any changes
14
14
  if update.length > 0
@@ -24,4 +24,4 @@ module Invoiced
24
24
  end
25
25
  end
26
26
  end
27
- end
27
+ end
@@ -1,6 +1,5 @@
1
1
  module Invoiced
2
2
  class PaymentPlan < Object
3
- include Invoiced::Operations::List
4
3
  include Invoiced::Operations::Delete
5
4
 
6
5
  def initialize(client, id=nil, values={})
@@ -0,0 +1,8 @@
1
+ module Invoiced
2
+ class Plan < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Invoiced
2
- VERSION = '0.9.0'
2
+ VERSION = '0.10.0'
3
3
  end
data/lib/invoiced.rb CHANGED
@@ -18,6 +18,7 @@ require 'invoiced/operations/update'
18
18
 
19
19
  require 'invoiced/object'
20
20
  require 'invoiced/attachment'
21
+ require 'invoiced/catalog_item'
21
22
  require 'invoiced/contact'
22
23
  require 'invoiced/credit_note'
23
24
  require 'invoiced/customer'
@@ -28,6 +29,7 @@ require 'invoiced/file'
28
29
  require 'invoiced/invoice'
29
30
  require 'invoiced/line_item'
30
31
  require 'invoiced/payment_plan'
32
+ require 'invoiced/plan'
31
33
  require 'invoiced/subscription'
32
34
  require 'invoiced/transaction'
33
35
 
@@ -37,7 +39,7 @@ module Invoiced
37
39
  ApiBaseSandbox = 'https://api.sandbox.invoiced.com'
38
40
 
39
41
  attr_reader :api_key, :api_url, :sandbox
40
- attr_reader :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Subscription, :Transaction
42
+ attr_reader :CatalogItem, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Plan, :Subscription, :Transaction
41
43
 
42
44
  def initialize(api_key, sandbox=false)
43
45
  @api_key = api_key
@@ -45,12 +47,14 @@ module Invoiced
45
47
  @api_url = sandbox ? ApiBaseSandbox : ApiBase
46
48
 
47
49
  # Object endpoints
50
+ @CatalogItem = Invoiced::CatalogItem.new(self)
48
51
  @CreditNote = Invoiced::CreditNote.new(self)
49
52
  @Customer = Invoiced::Customer.new(self)
50
53
  @Estimate = Invoiced::Estimate.new(self)
51
54
  @Event = Invoiced::Event.new(self)
52
55
  @File = Invoiced::File.new(self)
53
56
  @Invoice = Invoiced::Invoice.new(self)
57
+ @Plan = Invoiced::Plan.new(self)
54
58
  @Subscription = Invoiced::Subscription.new(self)
55
59
  @Transaction = Invoiced::Transaction.new(self)
56
60
  end
@@ -0,0 +1,90 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class CatalogItemTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ catalogItem = CatalogItem.new(@client, "test")
7
+ assert_equal('/catalog_items/test', catalogItem.endpoint())
8
+ end
9
+
10
+ should "create a catalog item" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":"test","name":"Test Item"}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ catalogItem = @client.CatalogItem.create({:name => "Test Item"})
19
+
20
+ assert_instance_of(Invoiced::CatalogItem, catalogItem)
21
+ assert_equal("test", catalogItem.id)
22
+ assert_equal('Test Item', catalogItem.name)
23
+ end
24
+
25
+ should "retrieve a catalog item" do
26
+ mockResponse = mock('RestClient::Response')
27
+ mockResponse.stubs(:code).returns(200)
28
+ mockResponse.stubs(:body).returns('{"id":"test","name":"Test Item"}')
29
+ mockResponse.stubs(:headers).returns({})
30
+
31
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
+
33
+ catalogItem = @client.CatalogItem.retrieve("test")
34
+
35
+ assert_instance_of(Invoiced::CatalogItem, catalogItem)
36
+ assert_equal("test", catalogItem.id)
37
+ assert_equal('Test Item', catalogItem.name)
38
+ end
39
+
40
+ should "not update a catalog item when no params" do
41
+ catalogItem = CatalogItem.new(@client, "test")
42
+ assert_false(catalogItem.save)
43
+ end
44
+
45
+ should "update a catalog item" do
46
+ mockResponse = mock('RestClient::Response')
47
+ mockResponse.stubs(:code).returns(200)
48
+ mockResponse.stubs(:body).returns('{"id":"test","closed":true}')
49
+ mockResponse.stubs(:headers).returns({})
50
+
51
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
+
53
+ catalogItem = CatalogItem.new(@client, "test")
54
+ catalogItem.closed = true
55
+ assert_true(catalogItem.save)
56
+
57
+ assert_true(catalogItem.closed)
58
+ end
59
+
60
+ should "list all catalog items" do
61
+ mockResponse = mock('RestClient::Response')
62
+ mockResponse.stubs(:code).returns(200)
63
+ mockResponse.stubs(:body).returns('[{"id":"test","name":"Test Item"}]')
64
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/catalog_items?per_page=25&page=1>; rel="self", <https://api.invoiced.com/catalog_items?per_page=25&page=1>; rel="first", <https://api.invoiced.com/catalog_items?per_page=25&page=1>; rel="last"')
65
+
66
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
+
68
+ catalogItems, metadata = @client.CatalogItem.list
69
+
70
+ assert_instance_of(Array, catalogItems)
71
+ assert_equal(1, catalogItems.length)
72
+ assert_equal("test", catalogItems[0].id)
73
+
74
+ assert_instance_of(Invoiced::List, metadata)
75
+ assert_equal(15, metadata.total_count)
76
+ end
77
+
78
+ should "delete a catalog item" do
79
+ mockResponse = mock('RestClient::Response')
80
+ mockResponse.stubs(:code).returns(204)
81
+ mockResponse.stubs(:body).returns('')
82
+ mockResponse.stubs(:headers).returns({})
83
+
84
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
85
+
86
+ catalogItem = CatalogItem.new(@client, "test")
87
+ assert_true(catalogItem.delete)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,90 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class PlanTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ plan = Plan.new(@client, "test")
7
+ assert_equal('/plans/test', plan.endpoint())
8
+ end
9
+
10
+ should "create a plan" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":"test","name":"Test Plan"}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ plan = @client.Plan.create({:name => "Test Plan"})
19
+
20
+ assert_instance_of(Invoiced::Plan, plan)
21
+ assert_equal("test", plan.id)
22
+ assert_equal('Test Plan', plan.name)
23
+ end
24
+
25
+ should "retrieve a plan" do
26
+ mockResponse = mock('RestClient::Response')
27
+ mockResponse.stubs(:code).returns(200)
28
+ mockResponse.stubs(:body).returns('{"id":"test","name":"Test Plan"}')
29
+ mockResponse.stubs(:headers).returns({})
30
+
31
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
+
33
+ plan = @client.Plan.retrieve("test")
34
+
35
+ assert_instance_of(Invoiced::Plan, plan)
36
+ assert_equal("test", plan.id)
37
+ assert_equal('Test Plan', plan.name)
38
+ end
39
+
40
+ should "not update a plan when no params" do
41
+ plan = Plan.new(@client, "test")
42
+ assert_false(plan.save)
43
+ end
44
+
45
+ should "update a plan" do
46
+ mockResponse = mock('RestClient::Response')
47
+ mockResponse.stubs(:code).returns(200)
48
+ mockResponse.stubs(:body).returns('{"id":"test","closed":true}')
49
+ mockResponse.stubs(:headers).returns({})
50
+
51
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
+
53
+ plan = Plan.new(@client, "test")
54
+ plan.closed = true
55
+ assert_true(plan.save)
56
+
57
+ assert_true(plan.closed)
58
+ end
59
+
60
+ should "list all plans" do
61
+ mockResponse = mock('RestClient::Response')
62
+ mockResponse.stubs(:code).returns(200)
63
+ mockResponse.stubs(:body).returns('[{"id":"test","name":"Test Plan"}]')
64
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/plans?per_page=25&page=1>; rel="self", <https://api.invoiced.com/plans?per_page=25&page=1>; rel="first", <https://api.invoiced.com/plans?per_page=25&page=1>; rel="last"')
65
+
66
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
+
68
+ plans, metadata = @client.Plan.list
69
+
70
+ assert_instance_of(Array, plans)
71
+ assert_equal(1, plans.length)
72
+ assert_equal("test", plans[0].id)
73
+
74
+ assert_instance_of(Invoiced::List, metadata)
75
+ assert_equal(15, metadata.total_count)
76
+ end
77
+
78
+ should "delete a plan" do
79
+ mockResponse = mock('RestClient::Response')
80
+ mockResponse.stubs(:code).returns(204)
81
+ mockResponse.stubs(:body).returns('')
82
+ mockResponse.stubs(:headers).returns({})
83
+
84
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
85
+
86
+ plan = Plan.new(@client, "test")
87
+ assert_true(plan.delete)
88
+ end
89
+ end
90
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoiced
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared King
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-16 00:00:00.000000000 Z
11
+ date: 2017-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -123,6 +123,7 @@ files:
123
123
  - invoiced.gemspec
124
124
  - lib/invoiced.rb
125
125
  - lib/invoiced/attachment.rb
126
+ - lib/invoiced/catalog_item.rb
126
127
  - lib/invoiced/contact.rb
127
128
  - lib/invoiced/credit_note.rb
128
129
  - lib/invoiced/customer.rb
@@ -144,10 +145,12 @@ files:
144
145
  - lib/invoiced/operations/list.rb
145
146
  - lib/invoiced/operations/update.rb
146
147
  - lib/invoiced/payment_plan.rb
148
+ - lib/invoiced/plan.rb
147
149
  - lib/invoiced/subscription.rb
148
150
  - lib/invoiced/transaction.rb
149
151
  - lib/invoiced/util.rb
150
152
  - lib/invoiced/version.rb
153
+ - test/invoiced/catalog_item_test.rb
151
154
  - test/invoiced/contact_test.rb
152
155
  - test/invoiced/credit_note_test.rb
153
156
  - test/invoiced/customer_test.rb
@@ -160,6 +163,7 @@ files:
160
163
  - test/invoiced/line_item_test.rb
161
164
  - test/invoiced/object_test.rb
162
165
  - test/invoiced/payment_plan_test.rb
166
+ - test/invoiced/plan_test.rb
163
167
  - test/invoiced/subscription_test.rb
164
168
  - test/invoiced/transaction_test.rb
165
169
  - test/invoiced/util_test.rb
@@ -189,6 +193,7 @@ signing_key:
189
193
  specification_version: 4
190
194
  summary: Ruby client library for the Invoiced API
191
195
  test_files:
196
+ - test/invoiced/catalog_item_test.rb
192
197
  - test/invoiced/contact_test.rb
193
198
  - test/invoiced/credit_note_test.rb
194
199
  - test/invoiced/customer_test.rb
@@ -201,6 +206,7 @@ test_files:
201
206
  - test/invoiced/line_item_test.rb
202
207
  - test/invoiced/object_test.rb
203
208
  - test/invoiced/payment_plan_test.rb
209
+ - test/invoiced/plan_test.rb
204
210
  - test/invoiced/subscription_test.rb
205
211
  - test/invoiced/transaction_test.rb
206
212
  - test/invoiced/util_test.rb