invoicexpress 0.1.8 → 0.1.9

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.
data/README.md CHANGED
@@ -41,7 +41,7 @@ Run bundle, the project should need:
41
41
  * Sim. Invoices - 100%
42
42
  * Credit Notes - 100%
43
43
  * Purch. Orders - 100%
44
-
44
+
45
45
  ## Documentation
46
46
 
47
47
  We've included docs for all methods. Refer to the doc folder and client section.
@@ -51,9 +51,9 @@ We've included docs for all methods. Refer to the doc folder and client section.
51
51
  If using from inside a rails project use:
52
52
 
53
53
  require 'invoicexpress'
54
-
54
+
55
55
  client = Invoicexpress::Client.new(
56
- :screen_name => "yourusername",
56
+ :account_name => "yourusername",
57
57
  :api_key => "yourapikey"
58
58
  )
59
59
 
@@ -51,6 +51,6 @@ module Invoicexpress
51
51
  include Invoicexpress::Client::DebitNotes
52
52
  include Invoicexpress::Client::CreditNotes
53
53
  include Invoicexpress::Client::SimplifiedInvoices
54
-
54
+
55
55
  end
56
56
  end
@@ -3,7 +3,7 @@ require 'invoicexpress/models'
3
3
  module Invoicexpress
4
4
  class Client
5
5
  module Invoices
6
-
6
+
7
7
  # Returns all your invoices
8
8
  #
9
9
  # @option options [Integer] page (1) You can ask a specific page of invoices
@@ -106,8 +106,6 @@ module Invoicexpress
106
106
  def invoice_email(invoice_id, message, options={})
107
107
  email_invoice(invoice_id, message, options)
108
108
  end
109
-
110
-
111
109
  end
112
110
  end
113
111
  end
@@ -7,6 +7,7 @@ module Invoicexpress
7
7
  :adapter,
8
8
  :faraday_config_block,
9
9
  :api_endpoint,
10
+ :account_name,
10
11
  :screen_name,
11
12
  :proxy,
12
13
  :api_key,
@@ -44,6 +45,7 @@ module Invoicexpress
44
45
  self.api_endpoint = DEFAULT_API_ENDPOINT
45
46
  self.user_agent = DEFAULT_USER_AGENT
46
47
  self.api_key = nil
48
+ self.account_name = nil
47
49
  self.screen_name = nil
48
50
  self.proxy = nil
49
51
  end
@@ -35,6 +35,5 @@ module Invoicexpress
35
35
  connection.headers[:user_agent] = user_agent
36
36
  connection
37
37
  end
38
-
39
38
  end
40
39
  end
@@ -38,7 +38,7 @@ module Invoicexpress
38
38
  private
39
39
 
40
40
  def build_error_message
41
- return nil if @response.nil?
41
+ return nil if @response.nil?
42
42
 
43
43
  message = if response_body
44
44
  if response_body.respond_to?(:errors)
@@ -65,4 +65,7 @@ module Invoicexpress
65
65
 
66
66
  # Raised when Invoicexpress server goes dark (500 HTTP status code)
67
67
  class InternalServerError < Error; end
68
+
69
+ # Raised when Invoicexpress server address could not be resolved
70
+ class BadAddress < Error; end
68
71
  end
@@ -22,8 +22,8 @@ module Invoicexpress
22
22
  end
23
23
 
24
24
  private
25
-
26
- # Executes the request, checking if ti was successful
25
+
26
+ # Executes the request, checking if it was successful
27
27
  #
28
28
  # @return [Boolean] True on success, false otherwise
29
29
  def boolean_from_response(method, path, options={})
@@ -34,7 +34,7 @@ module Invoicexpress
34
34
 
35
35
  def request(method, path, options={})
36
36
  token = options.delete(:api_key) || api_key
37
- url = options.delete(:endpoint) || (api_endpoint % screen_name)
37
+ url = options.delete(:endpoint) || (api_endpoint % account_domain)
38
38
  klass = options.delete(:klass) || raise(ArgumentError, "Need a HappyMapper class to parse")
39
39
 
40
40
  conn_options = {
@@ -57,7 +57,17 @@ module Invoicexpress
57
57
  end
58
58
 
59
59
  response
60
+ rescue Faraday::ConnectionFailed => e
61
+ unless e.message.match(/getaddrinfo/).nil?
62
+ raise Invoicexpress::BadAddress.new,
63
+ "Did you forget to set your account_name? Error: #{e.message}"
64
+ end
65
+
66
+ raise e
60
67
  end
61
68
 
69
+ def account_domain
70
+ account_name || screen_name
71
+ end
62
72
  end
63
73
  end
@@ -1,5 +1,5 @@
1
1
  module Invoicexpress
2
- Invoicexpress::VERSION = "0.1.8"
2
+ Invoicexpress::VERSION = "0.1.9"
3
3
 
4
4
  VERSION = "0.0.0" unless defined?(Invoicexpress::VERSION)
5
5
  end
@@ -3,7 +3,7 @@ require 'helper'
3
3
  describe Invoicexpress::Client::Charts do
4
4
 
5
5
  before do
6
- @client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
6
+ @client = Invoicexpress::Client.new(:account_name => "thinkorangeteste")
7
7
  end
8
8
 
9
9
  describe ".invoicing_chart" do
@@ -29,10 +29,10 @@ describe Invoicexpress::Client::Charts do
29
29
  chart.graphs.count.should ==4
30
30
  #count values
31
31
  chart.graphs.first.values.count.should ==7
32
-
32
+
33
33
  end
34
34
  end
35
-
35
+
36
36
  describe ".top_clients" do
37
37
  it "Returns the top 5 clients." do
38
38
  stub_get("/api/charts/top-clients.xml").
@@ -43,7 +43,7 @@ describe Invoicexpress::Client::Charts do
43
43
  chart.clients.size.should ==1
44
44
  end
45
45
  end
46
-
46
+
47
47
  describe ".top_debtors" do
48
48
  it "Returns the top 5 debtors." do
49
49
  stub_get("/api/charts/top-debtors.xml").
@@ -3,7 +3,7 @@ require 'helper'
3
3
  describe Invoicexpress::Client::Clients do
4
4
 
5
5
  before do
6
- @client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
6
+ @client = Invoicexpress::Client.new(:account_name => "thinkorangeteste")
7
7
  end
8
8
 
9
9
  describe ".clients" do
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  describe Invoicexpress::Client::CreditNotes do
4
4
  before do
5
- @client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
5
+ @client = Invoicexpress::Client.new(:account_name => "thinkorangeteste")
6
6
  end
7
7
 
8
8
  describe ".credit_notes" do
@@ -21,7 +21,7 @@ describe Invoicexpress::Client::CreditNotes do
21
21
  stub_post("/credit_notes.xml").
22
22
  to_return(xml_response("credit_notes.create.xml"))
23
23
 
24
-
24
+
25
25
  cnote = Invoicexpress::Models::CreditNote.new(
26
26
  :date => Date.new(2013, 5, 1),
27
27
  :due_date => Date.new(2013, 6, 1),
@@ -84,7 +84,7 @@ describe Invoicexpress::Client::CreditNotes do
84
84
  expect { cnote = @client.update_credit_note_state(1423940, state) }.to_not raise_error
85
85
  end
86
86
  end
87
-
87
+
88
88
  describe ".credit_note_mail" do
89
89
  it "sends the credit note through email" do
90
90
  stub_put("/credit_notes/1423940/email-document.xml").
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  describe Invoicexpress::Client::Invoices do
4
4
  before do
5
- @client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
5
+ @client = Invoicexpress::Client.new(:account_name => "thinkorangeteste")
6
6
  end
7
7
 
8
8
  describe ".invoices" do
@@ -21,7 +21,7 @@ describe Invoicexpress::Client::Invoices do
21
21
  stub_post("/invoices.xml").
22
22
  to_return(xml_response("invoices.create.xml"))
23
23
 
24
-
24
+
25
25
  object = Invoicexpress::Models::Invoice.new(
26
26
  :date => Date.new(2013, 6, 18),
27
27
  :due_date => Date.new(2013, 6, 18),
@@ -79,7 +79,7 @@ describe Invoicexpress::Client::Invoices do
79
79
  }.to raise_error(ArgumentError)
80
80
  end
81
81
  end
82
-
82
+
83
83
  describe ".update_invoice_state" do
84
84
  it "updates the state" do
85
85
  stub_put("/invoices/1503698/change-state.xml").
@@ -91,7 +91,7 @@ describe Invoicexpress::Client::Invoices do
91
91
  expect { @client.update_invoice_state(1503698, state) }.to_not raise_error
92
92
  end
93
93
  end
94
-
94
+
95
95
  describe ".email_invoice" do
96
96
  it "sends the invoice through email" do
97
97
  stub_put("/invoice/1503698/email-invoice.xml").
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  describe Invoicexpress::Client::PurchaseOrders do
4
4
  before do
5
- @client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
5
+ @client = Invoicexpress::Client.new(:account_name => "thinkorangeteste")
6
6
  end
7
7
 
8
8
  describe ".purchase_orders" do
@@ -20,7 +20,7 @@ describe Invoicexpress::Client::PurchaseOrders do
20
20
  it "creates a new purchase order" do
21
21
  stub_post("/purchase_orders.xml").
22
22
  to_return(xml_response("po.create.xml"))
23
-
23
+
24
24
  object = Invoicexpress::Models::PurchaseOrder.new(
25
25
  :date => Date.new(2013, 5, 30),
26
26
  :due_date => Date.new(2013, 8, 8),
@@ -82,7 +82,7 @@ describe Invoicexpress::Client::PurchaseOrders do
82
82
  }.to raise_error(ArgumentError)
83
83
  end
84
84
  end
85
-
85
+
86
86
 
87
87
  describe ".update_purchase_order_state" do
88
88
  it "updates the state" do
@@ -96,7 +96,7 @@ describe Invoicexpress::Client::PurchaseOrders do
96
96
  expect { item = @client.update_purchase_order_state(1430338, state) }.to_not raise_error
97
97
  end
98
98
  end
99
-
99
+
100
100
  describe ".simplified_invoice_mail" do
101
101
  it "sends the invoice through email" do
102
102
  stub_put("/purchase_orders/1430338/email-document.xml").
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  describe Invoicexpress::Client::Schedules do
4
4
  before do
5
- @client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
5
+ @client = Invoicexpress::Client.new(:account_name => "thinkorangeteste")
6
6
  end
7
7
 
8
8
  describe ".schedules" do
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  describe Invoicexpress::Client::Sequences do
4
4
  before do
5
- @client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
5
+ @client = Invoicexpress::Client.new(:account_name => "thinkorangeteste")
6
6
  end
7
7
 
8
8
  describe ".sequences" do
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  describe Invoicexpress::Client::SimplifiedInvoices do
4
4
  before do
5
- @client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
5
+ @client = Invoicexpress::Client.new(:account_name => "thinkorangeteste")
6
6
  end
7
7
 
8
8
  describe ".simplified_invoices" do
@@ -21,7 +21,7 @@ describe Invoicexpress::Client::SimplifiedInvoices do
21
21
  stub_post("/simplified_invoices.xml").
22
22
  to_return(xml_response("simplified_invoices.create.xml"))
23
23
 
24
-
24
+
25
25
  object = Invoicexpress::Models::SimplifiedInvoice.new(
26
26
  :date => Date.new(2013, 5, 1),
27
27
  :due_date => Date.new(2013, 6, 1),
@@ -84,7 +84,7 @@ describe Invoicexpress::Client::SimplifiedInvoices do
84
84
  }.to raise_error(ArgumentError)
85
85
  end
86
86
  end
87
-
87
+
88
88
  describe ".update_simplified_invoice_state" do
89
89
  it "updates the state" do
90
90
  stub_put("/simplified_invoices/1425061/change-state.xml").
@@ -96,7 +96,7 @@ describe Invoicexpress::Client::SimplifiedInvoices do
96
96
  expect { item = @client.update_simplified_invoice_state(1425061, state) }.to_not raise_error
97
97
  end
98
98
  end
99
-
99
+
100
100
  describe ".simplified_invoice_mail" do
101
101
  it "sends the invoice through email" do
102
102
  stub_put("/simplified_invoices/1425061/email-document.xml").
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  describe Invoicexpress::Client::Taxes do
4
4
  before do
5
- @client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
5
+ @client = Invoicexpress::Client.new(:account_name => "thinkorangeteste")
6
6
  end
7
7
 
8
8
  describe ".taxes" do
@@ -3,7 +3,7 @@ require 'helper'
3
3
  describe Invoicexpress::Client::Clients do
4
4
 
5
5
  before do
6
- @client = Invoicexpress::Client.new(:screen_name => "thinkorangeteste")
6
+ @client = Invoicexpress::Client.new(:account_name => "thinkorangeteste")
7
7
  end
8
8
 
9
9
  describe ".login" do
@@ -27,12 +27,12 @@ describe Invoicexpress::Client::Clients do
27
27
  list.first.name.should == "thinkorangeteste"
28
28
  end
29
29
  end
30
-
30
+
31
31
  describe ".change-account" do
32
32
  it "changes the current account to the account id submitted" do
33
33
  stub_put("/users/change-account.xml").
34
34
  to_return(xml_response("users.change-account.xml"))
35
-
35
+
36
36
  expect { cnote = @client.change_account(13233) }.to_not raise_error
37
37
  end
38
38
  end
@@ -0,0 +1,72 @@
1
+ require 'helper'
2
+
3
+ RSpec.describe Invoicexpress::Request do
4
+ let (:path) { '' }
5
+ let (:klass) { Class.new { include HappyMapper } }
6
+
7
+ shared_examples 'an account_name validator' do
8
+ context 'given a client with no account_name' do
9
+ let (:client) { Invoicexpress.new }
10
+
11
+ before do
12
+ stub_request(:any, 'https://.app.invoicexpress.com/')
13
+ .to_raise(Faraday::ConnectionFailed.new(
14
+ 'getaddrinfo: nodename nor servname provided, or not known'))
15
+ end
16
+
17
+ it 'raises a BadAddress error with a helpful suggestion' do
18
+ expect { subject }.to raise_error(
19
+ Invoicexpress::BadAddress, /forget.+account_name/)
20
+ end
21
+ end
22
+
23
+ context 'given a client with options' do
24
+ let (:client) { Invoicexpress.new options }
25
+
26
+ before { stub_request :any, 'https://test.app.invoicexpress.com/' }
27
+
28
+ context 'given an account_name' do
29
+ let (:options) { { account_name: 'test' } }
30
+
31
+ it 'sets the correct account subdomain' do
32
+ subject
33
+ assert_requested :any, 'https://test.app.invoicexpress.com/', times: 1
34
+ end
35
+ end
36
+
37
+ context 'given an screen_name' do
38
+ let (:options) { { screen_name: 'test' } }
39
+
40
+ it 'sets the correct account subdomain' do
41
+ subject
42
+ assert_requested :any, 'https://test.app.invoicexpress.com/', times: 1
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ describe '.delete' do
49
+ subject (:delete) { client.delete path, klass: klass }
50
+ it_behaves_like 'an account_name validator'
51
+ end
52
+
53
+ describe '.get' do
54
+ subject (:get) { client.get path, klass: klass }
55
+ it_behaves_like 'an account_name validator'
56
+ end
57
+
58
+ describe '.patch' do
59
+ subject (:patch) { client.patch path, klass: klass }
60
+ it_behaves_like 'an account_name validator'
61
+ end
62
+
63
+ describe '.post' do
64
+ subject (:post) { client.post path, klass: klass }
65
+ it_behaves_like 'an account_name validator'
66
+ end
67
+
68
+ describe '.put' do
69
+ subject (:put) { client.put path, klass: klass }
70
+ it_behaves_like 'an account_name validator'
71
+ end
72
+ end
metadata CHANGED
@@ -1,93 +1,87 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: invoicexpress
3
- version: !ruby/object:Gem::Version
4
- hash: 11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.9
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 8
10
- version: 0.1.8
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Think Orange
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2015-08-10 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2015-12-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: bundler
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 1
32
- - 0
33
- version: "1.0"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
34
22
  type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: faraday
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday
32
+ requirement: !ruby/object:Gem::Requirement
40
33
  none: false
41
- requirements:
34
+ requirements:
42
35
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 27
45
- segments:
46
- - 0
47
- - 8
48
- version: "0.8"
36
+ - !ruby/object:Gem::Version
37
+ version: '0.8'
49
38
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: faraday_middleware
53
39
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.8'
46
+ - !ruby/object:Gem::Dependency
47
+ name: faraday_middleware
48
+ requirement: !ruby/object:Gem::Requirement
55
49
  none: false
56
- requirements:
50
+ requirements:
57
51
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 25
60
- segments:
61
- - 0
62
- - 9
63
- version: "0.9"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.9'
64
54
  type: :runtime
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: happymapper
68
55
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ - !ruby/object:Gem::Dependency
63
+ name: happymapper
64
+ requirement: !ruby/object:Gem::Requirement
70
65
  none: false
71
- requirements:
66
+ requirements:
72
67
  - - ~>
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- - 4
78
- version: "0.4"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.4'
79
70
  type: :runtime
80
- version_requirements: *id004
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.4'
81
78
  description: Simple wrapper for invoicexpress.com API
82
- email:
79
+ email:
83
80
  - info@thinkorange.pt
84
81
  executables: []
85
-
86
82
  extensions: []
87
-
88
83
  extra_rdoc_files: []
89
-
90
- files:
84
+ files:
91
85
  - CHANGELOG.md
92
86
  - README.md
93
87
  - Rakefile
@@ -185,44 +179,34 @@ files:
185
179
  - spec/invoicexpress/client/users_spec.rb
186
180
  - spec/invoicexpress/client_spec.rb
187
181
  - spec/invoicexpress/models/item_spec.rb
182
+ - spec/invoicexpress/request_spec.rb
188
183
  - spec/invoicexpress_spec.rb
189
- has_rdoc: true
190
184
  homepage: http://invoicexpress.com
191
- licenses:
185
+ licenses:
192
186
  - MIT
193
187
  post_install_message:
194
188
  rdoc_options: []
195
-
196
- require_paths:
189
+ require_paths:
197
190
  - lib
198
- required_ruby_version: !ruby/object:Gem::Requirement
191
+ required_ruby_version: !ruby/object:Gem::Requirement
199
192
  none: false
200
- requirements:
201
- - - ">="
202
- - !ruby/object:Gem::Version
203
- hash: 3
204
- segments:
205
- - 0
206
- version: "0"
207
- required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
208
198
  none: false
209
- requirements:
210
- - - ">="
211
- - !ruby/object:Gem::Version
212
- hash: 23
213
- segments:
214
- - 1
215
- - 3
216
- - 6
199
+ requirements:
200
+ - - ! '>='
201
+ - !ruby/object:Gem::Version
217
202
  version: 1.3.6
218
203
  requirements: []
219
-
220
204
  rubyforge_project:
221
- rubygems_version: 1.6.2
205
+ rubygems_version: 1.8.23.2
222
206
  signing_key:
223
207
  specification_version: 3
224
208
  summary: Simple wrapper for invoicexpress.com API
225
- test_files:
209
+ test_files:
226
210
  - spec/fixtures/charts.invoicing.xml
227
211
  - spec/fixtures/charts.quarterly-results.xml
228
212
  - spec/fixtures/charts.top-clients.xml
@@ -280,4 +264,6 @@ test_files:
280
264
  - spec/invoicexpress/client/users_spec.rb
281
265
  - spec/invoicexpress/client_spec.rb
282
266
  - spec/invoicexpress/models/item_spec.rb
267
+ - spec/invoicexpress/request_spec.rb
283
268
  - spec/invoicexpress_spec.rb
269
+ has_rdoc: