invoiced 0.4.0 → 0.5.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: fdb8e10bfea7bc299ee7b9d51d8c85ed70f80049
4
- data.tar.gz: 692c072e06fd655d9107068bb59f10a9891b126c
3
+ metadata.gz: e536c65fccac56b2d988c5fe3aaecbc5c4c68ef4
4
+ data.tar.gz: d88a8e2e379d5b83b3d422dfefbd90125df90876
5
5
  SHA512:
6
- metadata.gz: b91243bed87f00e30b922f6204f2216b859f5caed60008e54911db1b321c1b8f06de0076ee8b6f72afd3dbf45718fb2042658d481fdc98d71c459cfbd2be534c
7
- data.tar.gz: d175b2b4cf3e21564510a2d18840a1e05f0f04d09c759113712754dae968691e7482f9a33895d96dab12866108024e35d224a09efa12aa3be32f1f7871702ecc
6
+ metadata.gz: 1432a26201de6db700fc04eecdd012f10e75357bb19111c980f7044ffdb5ed5b0001c27d8b96f2ed9e922a7399e3316892468daf47b5ee6abae7621347ebe7c5
7
+ data.tar.gz: f0c8fe2b96eb1bd0c470a42bbe12ec736c6afa219511d4d19a1f768ab0ba848392c0ab31729670ac4884a81e43861f7f1c231615bb018acfa4fcd680e9033873
data/invoiced.gemspec CHANGED
@@ -9,9 +9,9 @@ Gem::Specification.new do |s|
9
9
  s.summary = "Ruby client library for the Invoiced API"
10
10
  s.description = "Invoiced makes invoicing and recurring billing dead simple"
11
11
  s.authors = ["Jared King"]
12
- s.email = 'api@invoiced.com'
12
+ s.email = 'support@invoiced.com'
13
13
  s.files = ["lib/invoiced.rb"]
14
- s.homepage = 'https://developers.invoiced.com'
14
+ s.homepage = 'https://invoiced.com/docs/dev'
15
15
  s.required_ruby_version = '>= 1.9.3'
16
16
 
17
17
  s.add_dependency('rest-client', '~> 1.8.0')
@@ -0,0 +1,4 @@
1
+ module Invoiced
2
+ class Attachment < Object
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Invoiced
2
+ class File < Object
3
+ include Invoiced::Operations::Create
4
+ include Invoiced::Operations::Delete
5
+ end
6
+ end
@@ -21,5 +21,26 @@ module Invoiced
21
21
 
22
22
  return response[:code] == 200
23
23
  end
24
+
25
+ def attachments(opts={})
26
+ response = @client.request(:get, "#{self.endpoint()}/attachments", opts)
27
+
28
+ # ensure each attachment has an ID
29
+ body = response[:body]
30
+ body.each do |attachment|
31
+ if !attachment.has_key?(:id)
32
+ attachment[:id] = attachment[:file][:id]
33
+ end
34
+ end
35
+
36
+ # build objects
37
+ attachment = Attachment.new(@client)
38
+ attachments = Util.build_objects(attachment, body)
39
+
40
+ # store the metadata from the list operation
41
+ metadata = Invoiced::List.new(response[:headers][:link], response[:headers][:x_total_count])
42
+
43
+ return attachments, metadata
44
+ end
24
45
  end
25
46
  end
@@ -1,3 +1,3 @@
1
1
  module Invoiced
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
data/lib/invoiced.rb CHANGED
@@ -17,9 +17,11 @@ require 'invoiced/operations/delete'
17
17
  require 'invoiced/operations/update'
18
18
 
19
19
  require 'invoiced/object'
20
+ require 'invoiced/attachment'
20
21
  require 'invoiced/contact'
21
22
  require 'invoiced/customer'
22
23
  require 'invoiced/email'
24
+ require 'invoiced/file'
23
25
  require 'invoiced/invoice'
24
26
  require 'invoiced/line_item'
25
27
  require 'invoiced/transaction'
@@ -31,13 +33,16 @@ module Invoiced
31
33
  ApiBaseSandbox = 'https://api.sandbox.invoiced.com'
32
34
 
33
35
  attr_reader :api_key, :api_url, :sandbox
34
- attr_reader :Customer, :Invoice, :Transaction, :Subscription
36
+ attr_reader :Customer, :File, :Invoice, :Transaction, :Subscription
35
37
 
36
38
  def initialize(api_key, sandbox=false)
37
39
  @api_key = api_key
38
40
  @sandbox = sandbox
39
41
  @api_url = sandbox ? ApiBaseSandbox : ApiBase
42
+
43
+ # Object endpoints
40
44
  @Customer = Invoiced::Customer.new(self)
45
+ @File = Invoiced::File.new(self)
41
46
  @Invoice = Invoiced::Invoice.new(self)
42
47
  @Transaction = Invoiced::Transaction.new(self)
43
48
  @Subscription = Invoiced::Subscription.new(self)
@@ -0,0 +1,54 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class FileTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ file = File.new(@client, 123)
7
+ assert_equal('/files/123', file.endpoint())
8
+ end
9
+
10
+ should "create a file" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":123,"name":"Filename"}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ file = File.new(@client)
19
+ file = file.create({:name => "Filename"})
20
+
21
+ assert_instance_of(Invoiced::File, file)
22
+ assert_equal(123, file.id)
23
+ assert_equal("Filename", file.name)
24
+ end
25
+
26
+ should "retrieve a file" do
27
+ mockResponse = mock('RestClient::Response')
28
+ mockResponse.stubs(:code).returns(200)
29
+ mockResponse.stubs(:body).returns('{"id":123,"name":"Filename"}')
30
+ mockResponse.stubs(:headers).returns({})
31
+
32
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
33
+
34
+ file = File.new(@client)
35
+ file = file.retrieve(123)
36
+
37
+ assert_instance_of(Invoiced::File, file)
38
+ assert_equal(123, file.id)
39
+ assert_equal("Filename", file.name)
40
+ end
41
+
42
+ should "delete a file" do
43
+ mockResponse = mock('RestClient::Response')
44
+ mockResponse.stubs(:code).returns(204)
45
+ mockResponse.stubs(:body).returns('')
46
+ mockResponse.stubs(:headers).returns({})
47
+
48
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
49
+
50
+ file = File.new(@client, 123)
51
+ assert_true(file.delete)
52
+ end
53
+ end
54
+ end
@@ -117,5 +117,24 @@ module Invoiced
117
117
 
118
118
  assert_true(invoice.paid)
119
119
  end
120
+
121
+ should "list all of the invoice's attachments" do
122
+ mockResponse = mock('RestClient::Response')
123
+ mockResponse.stubs(:code).returns(200)
124
+ mockResponse.stubs(:body).returns('[{"file":{"id":456}}]')
125
+ mockResponse.stubs(:headers).returns(:x_total_count => 10, :link => '<https://api.invoiced.com/invoices/123/attachments?per_page=25&page=1>; rel="self", <https://api.invoiced.com/invoices/123/attachments?per_page=25&page=1>; rel="first", <https://api.invoiced.com/invoices/123/attachments?per_page=25&page=1>; rel="last"')
126
+
127
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
128
+
129
+ invoice = Invoice.new(@client, 123)
130
+ attachments, metadata = invoice.attachments
131
+
132
+ assert_instance_of(Array, attachments)
133
+ assert_equal(1, attachments.length)
134
+ assert_equal(456, attachments[0].id)
135
+
136
+ assert_instance_of(Invoiced::List, metadata)
137
+ assert_equal(10, metadata.total_count)
138
+ end
120
139
  end
121
140
  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.4.0
4
+ version: 0.5.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-05-27 00:00:00.000000000 Z
11
+ date: 2016-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: Invoiced makes invoicing and recurring billing dead simple
112
- email: api@invoiced.com
112
+ email: support@invoiced.com
113
113
  executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []
@@ -122,6 +122,7 @@ files:
122
122
  - Rakefile
123
123
  - invoiced.gemspec
124
124
  - lib/invoiced.rb
125
+ - lib/invoiced/attachment.rb
125
126
  - lib/invoiced/contact.rb
126
127
  - lib/invoiced/customer.rb
127
128
  - lib/invoiced/email.rb
@@ -130,6 +131,7 @@ files:
130
131
  - lib/invoiced/error/authentication_error.rb
131
132
  - lib/invoiced/error/error_base.rb
132
133
  - lib/invoiced/error/invalid_request.rb
134
+ - lib/invoiced/file.rb
133
135
  - lib/invoiced/invoice.rb
134
136
  - lib/invoiced/line_item.rb
135
137
  - lib/invoiced/list.rb
@@ -145,6 +147,7 @@ files:
145
147
  - test/invoiced/contact_test.rb
146
148
  - test/invoiced/customer_test.rb
147
149
  - test/invoiced/error_test.rb
150
+ - test/invoiced/file_test.rb
148
151
  - test/invoiced/invoice_test.rb
149
152
  - test/invoiced/invoiced_test.rb
150
153
  - test/invoiced/line_item_test.rb
@@ -153,7 +156,7 @@ files:
153
156
  - test/invoiced/transaction_test.rb
154
157
  - test/invoiced/util_test.rb
155
158
  - test/test_helper.rb
156
- homepage: https://developers.invoiced.com
159
+ homepage: https://invoiced.com/docs/dev
157
160
  licenses:
158
161
  - MIT
159
162
  metadata: {}
@@ -181,6 +184,7 @@ test_files:
181
184
  - test/invoiced/contact_test.rb
182
185
  - test/invoiced/customer_test.rb
183
186
  - test/invoiced/error_test.rb
187
+ - test/invoiced/file_test.rb
184
188
  - test/invoiced/invoice_test.rb
185
189
  - test/invoiced/invoiced_test.rb
186
190
  - test/invoiced/line_item_test.rb