invoiced 0.3.2 → 0.4.0

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: f8645f3555b1e4518b8f2e37f00500d2346d4a05
4
- data.tar.gz: 29e3b4c7d5928436be985d562d56d31896ec3e98
3
+ metadata.gz: fdb8e10bfea7bc299ee7b9d51d8c85ed70f80049
4
+ data.tar.gz: 692c072e06fd655d9107068bb59f10a9891b126c
5
5
  SHA512:
6
- metadata.gz: ec193889670371a0eede342cd061ccb15be1a850aa82d7ce377eced3b5885addd86dba1566677c47927586c60547c21a6fc4407ba7f48da7c8372f70125243b4
7
- data.tar.gz: 1e78637e8ff80a7663d8f40c5802808e6520691355b7258b2fbae6fbeb01814f992391a39d25ed7b96594291939d71c256f42f97cf9ae6367288caf97ad15f21
6
+ metadata.gz: b91243bed87f00e30b922f6204f2216b859f5caed60008e54911db1b321c1b8f06de0076ee8b6f72afd3dbf45718fb2042658d481fdc98d71c459cfbd2be534c
7
+ data.tar.gz: d175b2b4cf3e21564510a2d18840a1e05f0f04d09c759113712754dae968691e7482f9a33895d96dab12866108024e35d224a09efa12aa3be32f1f7871702ecc
data/.travis.yml CHANGED
@@ -6,4 +6,7 @@ rvm:
6
6
  - 2.1
7
7
  - 2.2
8
8
 
9
- sudo: false
9
+ sudo: false
10
+
11
+ notifications:
12
+ email: false
@@ -0,0 +1,8 @@
1
+ module Invoiced
2
+ class Contact < 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
@@ -19,17 +19,9 @@ module Invoiced
19
19
  response[:body]
20
20
  end
21
21
 
22
- def subscriptions(opts={})
23
- response = @client.request(:get, "#{self.endpoint()}/subscriptions", opts)
24
-
25
- # build objects
26
- subscription = Subscription.new(@client)
27
- subscriptions = Util.build_objects(subscription, response[:body])
28
-
29
- # store the metadata from the list operation
30
- metadata = Invoiced::List.new(response[:headers][:link], response[:headers][:x_total_count])
31
-
32
- return subscriptions, metadata
22
+ def contacts(opts={})
23
+ contact = Contact.new(@client)
24
+ contact.set_endpoint_base(self.endpoint())
33
25
  end
34
26
 
35
27
  def line_items(opts={})
@@ -1,3 +1,3 @@
1
1
  module Invoiced
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/invoiced.rb CHANGED
@@ -17,6 +17,7 @@ require 'invoiced/operations/delete'
17
17
  require 'invoiced/operations/update'
18
18
 
19
19
  require 'invoiced/object'
20
+ require 'invoiced/contact'
20
21
  require 'invoiced/customer'
21
22
  require 'invoiced/email'
22
23
  require 'invoiced/invoice'
@@ -0,0 +1,93 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class ContactTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ contact = Contact.new(@client, 123)
7
+ assert_equal('/contacts/123', contact.endpoint())
8
+ end
9
+
10
+ should "create a contact" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":123,"name":"Nancy"}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ contact = Contact.new(@client)
19
+ contact = contact.create({:name => "Nancy"})
20
+
21
+ assert_instance_of(Invoiced::Contact, contact)
22
+ assert_equal(123, contact.id)
23
+ assert_equal("Nancy", contact.name)
24
+ end
25
+
26
+ should "retrieve a contact" do
27
+ mockResponse = mock('RestClient::Response')
28
+ mockResponse.stubs(:code).returns(200)
29
+ mockResponse.stubs(:body).returns('{"id":123,"name":"Nancy"}')
30
+ mockResponse.stubs(:headers).returns({})
31
+
32
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
33
+
34
+ contact = Contact.new(@client)
35
+ contact = contact.retrieve(123)
36
+
37
+ assert_instance_of(Invoiced::Contact, contact)
38
+ assert_equal(123, contact.id)
39
+ assert_equal("Nancy", contact.name)
40
+ end
41
+
42
+ should "not update a contact when no params" do
43
+ contact = Contact.new(@client, 123)
44
+ assert_false(contact.save)
45
+ end
46
+
47
+ should "update a contact" do
48
+ mockResponse = mock('RestClient::Response')
49
+ mockResponse.stubs(:code).returns(200)
50
+ mockResponse.stubs(:body).returns('{"id":123,"name":"Nancy Drew"}')
51
+ mockResponse.stubs(:headers).returns({})
52
+
53
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
54
+
55
+ contact = Contact.new(@client, 123)
56
+ contact.name = "Nancy Drew"
57
+ assert_true(contact.save)
58
+
59
+ assert_equal("Nancy Drew", contact.name)
60
+ end
61
+
62
+ should "list all contacts" do
63
+ mockResponse = mock('RestClient::Response')
64
+ mockResponse.stubs(:code).returns(200)
65
+ mockResponse.stubs(:body).returns('[{"id":123,"name":"Nancy"}]')
66
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/contacts?per_page=25&page=1>; rel="self", <https://api.invoiced.com/contacts?per_page=25&page=1>; rel="first", <https://api.invoiced.com/contacts?per_page=25&page=1>; rel="last"')
67
+
68
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
69
+
70
+ contact = Contact.new(@client)
71
+ contacts, metadata = contact.list
72
+
73
+ assert_instance_of(Array, contacts)
74
+ assert_equal(1, contacts.length)
75
+ assert_equal(123, contacts[0].id)
76
+
77
+ assert_instance_of(Invoiced::List, metadata)
78
+ assert_equal(15, metadata.total_count)
79
+ end
80
+
81
+ should "delete a contact" do
82
+ mockResponse = mock('RestClient::Response')
83
+ mockResponse.stubs(:code).returns(204)
84
+ mockResponse.stubs(:body).returns('')
85
+ mockResponse.stubs(:headers).returns({})
86
+
87
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
88
+
89
+ contact = Contact.new(@client, 123)
90
+ assert_true(contact.delete)
91
+ end
92
+ end
93
+ end
@@ -124,25 +124,60 @@ module Invoiced
124
124
  assert_equal(expected, balance)
125
125
  end
126
126
 
127
- should "list all of the customer's subscriptions" do
127
+ should "create a contact" do
128
+ mockResponse = mock('RestClient::Response')
129
+ mockResponse.stubs(:code).returns(201)
130
+ mockResponse.stubs(:body).returns('{"id":123,"name":"Nancy"}')
131
+ mockResponse.stubs(:headers).returns({})
132
+
133
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
134
+
135
+ customer = Customer.new(@client, 456)
136
+ contact = customer.contacts.create({:name => "Nancy"})
137
+
138
+ assert_instance_of(Invoiced::Contact, contact)
139
+ assert_equal(123, contact.id)
140
+ assert_equal("Nancy", contact.name)
141
+ assert_equal('/customers/456/contacts/123', contact.endpoint())
142
+ end
143
+
144
+ should "list all of the customer's contact" do
128
145
  mockResponse = mock('RestClient::Response')
129
146
  mockResponse.stubs(:code).returns(200)
130
- mockResponse.stubs(:body).returns('[{"id":123,"plan":456}]')
131
- mockResponse.stubs(:headers).returns(:x_total_count => 10, :link => '<https://api.invoiced.com/customers/123/subscriptions?per_page=25&page=1>; rel="self", <https://api.invoiced.com/customers/123/subscriptions?per_page=25&page=1>; rel="first", <https://api.invoiced.com/customers/123/subscriptions?per_page=25&page=1>; rel="last"')
147
+ mockResponse.stubs(:body).returns('[{"id":123,"name":"Nancy"}]')
148
+ mockResponse.stubs(:headers).returns(:x_total_count => 10, :link => '<https://api.invoiced.com/customers/123/contacts?per_page=25&page=1>; rel="self", <https://api.invoiced.com/customers/123/contacts?per_page=25&page=1>; rel="first", <https://api.invoiced.com/customers/123/contacts?per_page=25&page=1>; rel="last"')
132
149
 
133
150
  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
134
151
 
135
- customer = Customer.new(@client, 123)
136
- subscriptions, metadata = customer.subscriptions
152
+ customer = Customer.new(@client, 456)
153
+ contacts, metadata = customer.contacts.list
137
154
 
138
- assert_instance_of(Array, subscriptions)
139
- assert_equal(1, subscriptions.length)
140
- assert_equal(123, subscriptions[0].id)
155
+ assert_instance_of(Array, contacts)
156
+ assert_equal(1, contacts.length)
157
+ assert_equal(123, contacts[0].id)
158
+ assert_equal('/customers/456/contacts/123', contacts[0].endpoint())
141
159
 
142
160
  assert_instance_of(Invoiced::List, metadata)
143
161
  assert_equal(10, metadata.total_count)
144
162
  end
145
163
 
164
+ should "retrieve a contact" do
165
+ mockResponse = mock('RestClient::Response')
166
+ mockResponse.stubs(:code).returns(200)
167
+ mockResponse.stubs(:body).returns('{"id":123,"name":"Nancy"}')
168
+ mockResponse.stubs(:headers).returns({})
169
+
170
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
171
+
172
+ customer = Customer.new(@client, 456)
173
+ contact = customer.contacts.retrieve(123)
174
+
175
+ assert_instance_of(Invoiced::Contact, contact)
176
+ assert_equal(123, contact.id)
177
+ assert_equal("Nancy", contact.name)
178
+ assert_equal('/customers/456/contacts/123', contact.endpoint())
179
+ end
180
+
146
181
  should "create a pending line item" do
147
182
  mockResponse = mock('RestClient::Response')
148
183
  mockResponse.stubs(:code).returns(201)
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.3.2
4
+ version: 0.4.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: 2016-03-09 00:00:00.000000000 Z
11
+ date: 2016-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -122,6 +122,7 @@ files:
122
122
  - Rakefile
123
123
  - invoiced.gemspec
124
124
  - lib/invoiced.rb
125
+ - lib/invoiced/contact.rb
125
126
  - lib/invoiced/customer.rb
126
127
  - lib/invoiced/email.rb
127
128
  - lib/invoiced/error/api_connection_error.rb
@@ -141,6 +142,7 @@ files:
141
142
  - lib/invoiced/transaction.rb
142
143
  - lib/invoiced/util.rb
143
144
  - lib/invoiced/version.rb
145
+ - test/invoiced/contact_test.rb
144
146
  - test/invoiced/customer_test.rb
145
147
  - test/invoiced/error_test.rb
146
148
  - test/invoiced/invoice_test.rb
@@ -176,6 +178,7 @@ signing_key:
176
178
  specification_version: 4
177
179
  summary: Ruby client library for the Invoiced API
178
180
  test_files:
181
+ - test/invoiced/contact_test.rb
179
182
  - test/invoiced/customer_test.rb
180
183
  - test/invoiced/error_test.rb
181
184
  - test/invoiced/invoice_test.rb