quaderno 1.13.2 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +56 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +2 -15
  6. data/README.md +120 -42
  7. data/Rakefile +4 -50
  8. data/changelog.md +67 -41
  9. data/lib/quaderno-ruby.rb +5 -5
  10. data/lib/quaderno-ruby/base.rb +112 -107
  11. data/lib/quaderno-ruby/behavior/block.rb +20 -19
  12. data/lib/quaderno-ruby/behavior/crud.rb +108 -95
  13. data/lib/quaderno-ruby/behavior/deliver.rb +20 -18
  14. data/lib/quaderno-ruby/behavior/payment.rb +38 -34
  15. data/lib/quaderno-ruby/behavior/retrieve.rb +26 -25
  16. data/lib/quaderno-ruby/checkout_session.rb +4 -0
  17. data/lib/quaderno-ruby/collection.rb +1 -0
  18. data/lib/quaderno-ruby/contact.rb +6 -8
  19. data/lib/quaderno-ruby/credit.rb +10 -12
  20. data/lib/quaderno-ruby/document_item.rb +1 -3
  21. data/lib/quaderno-ruby/estimate.rb +5 -7
  22. data/lib/quaderno-ruby/evidence.rb +5 -7
  23. data/lib/quaderno-ruby/exceptions/exceptions.rb +50 -44
  24. data/lib/quaderno-ruby/expense.rb +6 -8
  25. data/lib/quaderno-ruby/helpers/authentication.rb +16 -18
  26. data/lib/quaderno-ruby/helpers/rate_limit.rb +12 -0
  27. data/lib/quaderno-ruby/income.rb +8 -10
  28. data/lib/quaderno-ruby/invoice.rb +9 -11
  29. data/lib/quaderno-ruby/item.rb +3 -6
  30. data/lib/quaderno-ruby/payment.rb +2 -3
  31. data/lib/quaderno-ruby/receipt.rb +6 -8
  32. data/lib/quaderno-ruby/recurring.rb +4 -7
  33. data/lib/quaderno-ruby/report.rb +67 -29
  34. data/lib/quaderno-ruby/tax.rb +51 -46
  35. data/lib/quaderno-ruby/version.rb +3 -0
  36. data/lib/quaderno-ruby/webhook.rb +3 -5
  37. data/quaderno.gemspec +28 -148
  38. metadata +92 -92
  39. data/Gemfile.lock +0 -91
  40. data/VERSION +0 -1
  41. data/test/fixtures/quaderno_cassettes/.DS_Store +0 -0
  42. data/test/fixtures/quaderno_cassettes/all_contacts.yml +0 -52
  43. data/test/fixtures/quaderno_cassettes/all_contacts_by_access_token.yml +0 -56
  44. data/test/fixtures/quaderno_cassettes/all_contacts_by_authentication_token.yml +0 -57
  45. data/test/fixtures/quaderno_cassettes/all_estimates.yml +0 -52
  46. data/test/fixtures/quaderno_cassettes/all_expenses.yml +0 -55
  47. data/test/fixtures/quaderno_cassettes/all_invoices.yml +0 -56
  48. data/test/fixtures/quaderno_cassettes/all_items.yml +0 -46
  49. data/test/fixtures/quaderno_cassettes/all_receipts.yml +0 -53
  50. data/test/fixtures/quaderno_cassettes/all_webhooks.yml +0 -214
  51. data/test/fixtures/quaderno_cassettes/create_estimate_on_downgraded_API.yml +0 -156
  52. data/test/fixtures/quaderno_cassettes/create_expense_on_downgraded_API.yml +0 -278
  53. data/test/fixtures/quaderno_cassettes/create_invoice_on_downgraded_API.yml +0 -159
  54. data/test/fixtures/quaderno_cassettes/create_receipt_on_downgraded_API.yml +0 -196
  55. data/test/fixtures/quaderno_cassettes/deleted_contact.yml +0 -187
  56. data/test/fixtures/quaderno_cassettes/deleted_contact_by_access_token.yml +0 -199
  57. data/test/fixtures/quaderno_cassettes/deleted_contact_by_authentication_token.yml +0 -199
  58. data/test/fixtures/quaderno_cassettes/deleted_estimate.yml +0 -187
  59. data/test/fixtures/quaderno_cassettes/deleted_expense.yml +0 -189
  60. data/test/fixtures/quaderno_cassettes/deleted_invoice.yml +0 -190
  61. data/test/fixtures/quaderno_cassettes/deleted_item.yml +0 -128
  62. data/test/fixtures/quaderno_cassettes/deleted_receipt.yml +0 -223
  63. data/test/fixtures/quaderno_cassettes/deleted_webhook.yml +0 -257
  64. data/test/fixtures/quaderno_cassettes/delivered_estimate.yml +0 -136
  65. data/test/fixtures/quaderno_cassettes/delivered_invoice.yml +0 -143
  66. data/test/fixtures/quaderno_cassettes/delivered_receipt.yml +0 -140
  67. data/test/fixtures/quaderno_cassettes/evidence_invoice.yml +0 -98
  68. data/test/fixtures/quaderno_cassettes/found_contact.yml +0 -95
  69. data/test/fixtures/quaderno_cassettes/found_contact_by_access_token.yml +0 -99
  70. data/test/fixtures/quaderno_cassettes/found_contact_by_authentication_token.yml +0 -100
  71. data/test/fixtures/quaderno_cassettes/found_estimate.yml +0 -97
  72. data/test/fixtures/quaderno_cassettes/found_expense.yml +0 -99
  73. data/test/fixtures/quaderno_cassettes/found_invoice.yml +0 -100
  74. data/test/fixtures/quaderno_cassettes/found_item.yml +0 -91
  75. data/test/fixtures/quaderno_cassettes/found_receipt.yml +0 -98
  76. data/test/fixtures/quaderno_cassettes/found_webhook.yml +0 -130
  77. data/test/fixtures/quaderno_cassettes/new_contact.yml +0 -48
  78. data/test/fixtures/quaderno_cassettes/new_contact_by_access_token.yml +0 -48
  79. data/test/fixtures/quaderno_cassettes/new_contact_by_authentication_token.yml +0 -48
  80. data/test/fixtures/quaderno_cassettes/new_estimate.yml +0 -137
  81. data/test/fixtures/quaderno_cassettes/new_evidence.yml +0 -48
  82. data/test/fixtures/quaderno_cassettes/new_expense.yml +0 -189
  83. data/test/fixtures/quaderno_cassettes/new_invoice.yml +0 -137
  84. data/test/fixtures/quaderno_cassettes/new_item.yml +0 -48
  85. data/test/fixtures/quaderno_cassettes/new_receipt.yml +0 -173
  86. data/test/fixtures/quaderno_cassettes/new_webhook.yml +0 -87
  87. data/test/fixtures/quaderno_cassettes/paid_expense.yml +0 -98
  88. data/test/fixtures/quaderno_cassettes/paid_invoice.yml +0 -99
  89. data/test/fixtures/quaderno_cassettes/rate_limit.yml +0 -46
  90. data/test/fixtures/quaderno_cassettes/unpay_an_expense.yml +0 -138
  91. data/test/fixtures/quaderno_cassettes/unpay_an_invoice.yml +0 -138
  92. data/test/fixtures/quaderno_cassettes/updated_contact.yml +0 -97
  93. data/test/fixtures/quaderno_cassettes/updated_contact_by_access_token.yml +0 -101
  94. data/test/fixtures/quaderno_cassettes/updated_contact_by_authentication_token.yml +0 -102
  95. data/test/fixtures/quaderno_cassettes/updated_estimate.yml +0 -185
  96. data/test/fixtures/quaderno_cassettes/updated_expense.yml +0 -184
  97. data/test/fixtures/quaderno_cassettes/updated_invoice.yml +0 -184
  98. data/test/fixtures/quaderno_cassettes/updated_item.yml +0 -93
  99. data/test/fixtures/quaderno_cassettes/updated_receipt.yml +0 -220
  100. data/test/fixtures/quaderno_cassettes/updated_webhook.yml +0 -175
  101. data/test/fixtures/quaderno_cassettes/validate_invalid_VAT_number.yml +0 -44
  102. data/test/fixtures/quaderno_cassettes/validate_valid_VAT_number.yml +0 -44
  103. data/test/helper.rb +0 -32
  104. data/test/unit/test_quaderno_contacts.rb +0 -83
  105. data/test/unit/test_quaderno_contacts_thread_safe.rb +0 -104
  106. data/test/unit/test_quaderno_estimates.rb +0 -155
  107. data/test/unit/test_quaderno_evidences.rb +0 -41
  108. data/test/unit/test_quaderno_expenses.rb +0 -162
  109. data/test/unit/test_quaderno_invoices.rb +0 -177
  110. data/test/unit/test_quaderno_items.rb +0 -84
  111. data/test/unit/test_quaderno_receipts.rb +0 -156
  112. data/test/unit/test_quaderno_tax.rb +0 -46
  113. data/test/unit/test_quaderno_webhooks.rb +0 -93
@@ -1,175 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: post
5
- uri: http://sk_test_B7xXrTspfeGukQqGN1pK@development.lvh.me:3000/api/webhooks.json
6
- body:
7
- encoding: UTF-8
8
- string: '{"url":"http://quadernoapp.com","events_types":["invoice.created","expense.updated"]}'
9
- headers:
10
- accept:
11
- - application/json
12
- content-type:
13
- - application/json
14
- authorization:
15
- - Basic c2tfdGVzdF9CN3hYclRzcGZlR3VrUXFHTjFwSzo=
16
- response:
17
- status:
18
- code: 201
19
- message: Created
20
- headers:
21
- x-frame-options:
22
- - ALLOWALL
23
- x-ratelimit-limit:
24
- - '2000'
25
- x-ratelimit-reset:
26
- - '7'
27
- x-ratelimit-remaining:
28
- - '93'
29
- content-type:
30
- - application/json; charset=utf-8
31
- etag:
32
- - '"50272ad49799cb72cebe932d58808877"'
33
- cache-control:
34
- - max-age=0, private, must-revalidate
35
- x-request-id:
36
- - c057b4fb-bdd8-49a4-8fd6-ef2e6eceb20f
37
- x-runtime:
38
- - '1.872855'
39
- connection:
40
- - close
41
- server:
42
- - thin
43
- body:
44
- encoding: UTF-8
45
- string: '{"id":8,"url":"http://quadernoapp.com","auth_key":"JL-KguI89KWWPQfx-j_jVQ","events_types":["invoice.created","expense.updated"],"last_sent_at":null,"last_error":null,"events_sent":0,"created_at":"2017-06-12T11:54:33.493Z","updated_at":"2017-06-12T11:54:33.493Z"}'
46
- http_version: '1.1'
47
- recorded_at: Mon, 12 Jun 2017 11:54:33 GMT
48
- - request:
49
- method: get
50
- uri: http://sk_test_B7xXrTspfeGukQqGN1pK@development.lvh.me:3000/api/webhooks.json?
51
- body:
52
- encoding: US-ASCII
53
- string: ''
54
- headers:
55
- accept:
56
- - application/json
57
- authorization:
58
- - Basic c2tfdGVzdF9CN3hYclRzcGZlR3VrUXFHTjFwSzo=
59
- response:
60
- status:
61
- code: 200
62
- message: OK
63
- headers:
64
- x-frame-options:
65
- - ALLOWALL
66
- x-ratelimit-limit:
67
- - '2000'
68
- x-ratelimit-reset:
69
- - '5'
70
- x-ratelimit-remaining:
71
- - '92'
72
- content-type:
73
- - application/json; charset=utf-8
74
- etag:
75
- - '"5096b6af7b77b2a57d706dd1434b3970"'
76
- cache-control:
77
- - max-age=0, private, must-revalidate
78
- x-request-id:
79
- - 81b27380-7fc2-42dd-b974-e2c93f9d2315
80
- x-runtime:
81
- - '0.645302'
82
- connection:
83
- - close
84
- server:
85
- - thin
86
- body:
87
- encoding: UTF-8
88
- string: '[{"id":1,"url":"http://quadernoapp.com","auth_key":"Ze024XpO9CJ6Fy2frwWV4Q","events_types":["invoice.created","expense.updated"],"last_sent_at":null,"last_error":null,"events_sent":0,"created_at":"2017-06-12T11:53:54.000Z","updated_at":"2017-06-12T11:53:54.000Z"},{"id":8,"url":"http://quadernoapp.com","auth_key":"JL-KguI89KWWPQfx-j_jVQ","events_types":["invoice.created","expense.updated"],"last_sent_at":null,"last_error":null,"events_sent":0,"created_at":"2017-06-12T11:54:33.000Z","updated_at":"2017-06-12T11:54:33.000Z"}]'
89
- http_version: '1.1'
90
- recorded_at: Mon, 12 Jun 2017 11:54:34 GMT
91
- - request:
92
- method: put
93
- uri: http://sk_test_B7xXrTspfeGukQqGN1pK@development.lvh.me:3000/api/webhooks/8.json
94
- body:
95
- encoding: UTF-8
96
- string: '{"events_types":["invoice.created","invoice.updated","contact.deleted"]}'
97
- headers:
98
- accept:
99
- - application/json
100
- content-type:
101
- - application/json
102
- authorization:
103
- - Basic c2tfdGVzdF9CN3hYclRzcGZlR3VrUXFHTjFwSzo=
104
- response:
105
- status:
106
- code: 200
107
- message: OK
108
- headers:
109
- x-frame-options:
110
- - ALLOWALL
111
- x-ratelimit-limit:
112
- - '2000'
113
- x-ratelimit-reset:
114
- - '4'
115
- x-ratelimit-remaining:
116
- - '91'
117
- content-type:
118
- - application/json; charset=utf-8
119
- etag:
120
- - '"926cdf82d9b90ab6c43e3b76c7cbb096"'
121
- cache-control:
122
- - max-age=0, private, must-revalidate
123
- x-request-id:
124
- - 4ac6d2cf-c1e5-48fc-81e8-20f745a84040
125
- x-runtime:
126
- - '1.871170'
127
- connection:
128
- - close
129
- server:
130
- - thin
131
- body:
132
- encoding: UTF-8
133
- string: '{"id":8,"url":"http://quadernoapp.com","auth_key":"JL-KguI89KWWPQfx-j_jVQ","events_types":["invoice.created","invoice.updated","contact.deleted"],"last_sent_at":null,"last_error":null,"events_sent":0,"created_at":"2017-06-12T11:54:33.000Z","updated_at":"2017-06-12T11:54:36.369Z"}'
134
- http_version: '1.1'
135
- recorded_at: Mon, 12 Jun 2017 11:54:36 GMT
136
- - request:
137
- method: delete
138
- uri: http://sk_test_B7xXrTspfeGukQqGN1pK@development.lvh.me:3000/api/webhooks/8.json
139
- body:
140
- encoding: US-ASCII
141
- string: ''
142
- headers:
143
- accept:
144
- - application/json
145
- authorization:
146
- - Basic c2tfdGVzdF9CN3hYclRzcGZlR3VrUXFHTjFwSzo=
147
- response:
148
- status:
149
- code: 204
150
- message: No Content
151
- headers:
152
- x-frame-options:
153
- - ALLOWALL
154
- x-ratelimit-limit:
155
- - '2000'
156
- x-ratelimit-reset:
157
- - '2'
158
- x-ratelimit-remaining:
159
- - '90'
160
- cache-control:
161
- - no-cache
162
- x-request-id:
163
- - 70e6bc87-63f8-456a-a42f-3ac79d407e94
164
- x-runtime:
165
- - '0.936896'
166
- connection:
167
- - close
168
- server:
169
- - thin
170
- body:
171
- encoding: US-ASCII
172
- string: ''
173
- http_version: '1.1'
174
- recorded_at: Mon, 12 Jun 2017 11:54:37 GMT
175
- recorded_with: VCR 2.9.2
@@ -1,44 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: http://sk_test_B7xXrTspfeGukQqGN1pK@development.lvh.me:3000/api/taxes/validate.json?country=IE&vat_number=IE6388047X
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- authorization:
11
- - Basic c2tfdGVzdF9CN3hYclRzcGZlR3VrUXFHTjFwSzo=
12
- response:
13
- status:
14
- code: 200
15
- message: OK
16
- headers:
17
- x-frame-options:
18
- - ALLOWALL
19
- x-ratelimit-limit:
20
- - '2000'
21
- x-ratelimit-reset:
22
- - '14'
23
- x-ratelimit-remaining:
24
- - '98'
25
- content-type:
26
- - application/json; charset=utf-8
27
- etag:
28
- - '"fe2f663bfba92bdd59b4bd0190a146b7"'
29
- cache-control:
30
- - max-age=0, private, must-revalidate
31
- x-request-id:
32
- - 21922ced-169f-4a23-ac48-94b3c86d47d7
33
- x-runtime:
34
- - '0.444012'
35
- connection:
36
- - close
37
- server:
38
- - thin
39
- body:
40
- encoding: UTF-8
41
- string: '{"valid":false}'
42
- http_version: '1.1'
43
- recorded_at: Tue, 30 Aug 2016 10:38:15 GMT
44
- recorded_with: VCR 2.9.2
@@ -1,44 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: http://sk_test_B7xXrTspfeGukQqGN1pK@development.lvh.me:3000/api/taxes/validate.json?country=IE&vat_number=IE6388047V
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- authorization:
11
- - Basic c2tfdGVzdF9CN3hYclRzcGZlR3VrUXFHTjFwSzo=
12
- response:
13
- status:
14
- code: 200
15
- message: OK
16
- headers:
17
- x-frame-options:
18
- - ALLOWALL
19
- x-ratelimit-limit:
20
- - '2000'
21
- x-ratelimit-reset:
22
- - '15'
23
- x-ratelimit-remaining:
24
- - '99'
25
- content-type:
26
- - application/json; charset=utf-8
27
- etag:
28
- - '"39837b2fcec9d416bda32e66244da470"'
29
- cache-control:
30
- - max-age=0, private, must-revalidate
31
- x-request-id:
32
- - 2153abc6-2f6e-47da-9f37-f4edb50b16a9
33
- x-runtime:
34
- - '2.047779'
35
- connection:
36
- - close
37
- server:
38
- - thin
39
- body:
40
- encoding: UTF-8
41
- string: '{"valid":true}'
42
- http_version: '1.1'
43
- recorded_at: Tue, 30 Aug 2016 10:38:15 GMT
44
- recorded_with: VCR 2.9.2
@@ -1,32 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
-
4
- require 'rubygems'
5
- require 'bundler'
6
-
7
- begin
8
- Bundler.setup(:default, :test)
9
- rescue Bundler::BundlerError => e
10
- $stderr.puts e.message
11
- $stderr.puts "Run `bundle install` to install missing gems"
12
- exit e.status_code
13
- end
14
-
15
- require 'vcr'
16
- require 'test/unit'
17
- require 'shoulda-context'
18
- require 'quaderno-ruby'
19
-
20
- VCR.configure do |c|
21
- c.cassette_library_dir = 'test/fixtures/quaderno_cassettes'
22
- c.ignore_localhost = false
23
- c.hook_into :fakeweb
24
- end
25
-
26
- TEST_URL = 'http://development.lvh.me:3000/api/'
27
- TEST_KEY = 'sk_test_B7xXrTspfeGukQqGN1pK'
28
- TEST_OAUTH_ACCESS_TOKEN = '36b82411e6686581fe3d7d10fbe931a3fdc9265a353832f0e3ff6269bd319e12'
29
- OLDEST_SUPPORTED_API_VERSION = 20160602
30
-
31
- class Test::Unit::TestCase
32
- end
@@ -1,83 +0,0 @@
1
- require 'helper'
2
-
3
- class TestQuadernoContact < Test::Unit::TestCase
4
-
5
- context 'using the default configuration with an authentication token' do
6
- setup do
7
- Quaderno::Base.configure do |config|
8
- config.auth_token = TEST_KEY
9
- config.url = TEST_URL
10
- config.api_version = nil
11
- end
12
- end
13
-
14
- should 'get exception if pass wrong arguments' do
15
- assert_raise ArgumentError do
16
- VCR.use_cassette('all contacts') do
17
- Quaderno::Contact.all 1, 2, 3
18
- end
19
- end
20
- assert_raise ArgumentError do
21
- VCR.use_cassette('found contact') do
22
- Quaderno::Contact.find
23
- end
24
- end
25
- end
26
-
27
- should 'get all contacts (populated db)' do
28
- VCR.use_cassette('all contacts') do
29
- contacts = Quaderno::Contact.all
30
- assert_not_nil contacts
31
- assert_kind_of Array, contacts
32
- contacts.each do |contact|
33
- assert_kind_of Quaderno::Contact, contact
34
- end
35
- end
36
- end
37
-
38
- should 'find a contact' do
39
- VCR.use_cassette('found contact') do
40
- contacts = Quaderno::Contact.all
41
- contact = Quaderno::Contact.find contacts[2].id
42
- assert_kind_of Quaderno::Contact, contact
43
- assert_equal contacts[2].id, contact.id
44
- end
45
- end
46
-
47
- should 'create a contact' do
48
- VCR.use_cassette('new contact') do
49
- contact = Quaderno::Contact.create(kind: 'company', first_name: 'Test_Skynet', email: 'my_little@po.ny')
50
- assert_kind_of Quaderno::Contact, contact
51
- assert_equal 'company', contact.kind
52
- assert_equal 'Test_Skynet', contact.full_name
53
- end
54
- end
55
-
56
- should 'update a contact' do
57
- VCR.use_cassette('updated contact') do
58
- contacts = Quaderno::Contact.all
59
- contact = Quaderno::Contact.update(contacts[2].id, first_name: 'Test_OCP', email: 'dont@stop.believing')
60
- assert_kind_of Quaderno::Contact, contact
61
- assert_equal 'Test_OCP', contact.first_name || contact.full_name
62
- end
63
- end
64
-
65
- should 'delete a contact' do
66
- VCR.use_cassette('deleted contact') do
67
- new_contact = Quaderno::Contact.create(kind: 'company', first_name: 'Z, Mazinger Z', email: 'koji@kabuto.ftw')
68
- contacts_before = Quaderno::Contact.all
69
- contact_id = contacts_before.last.id
70
- Quaderno::Contact.delete contact_id
71
- contacts_after = Quaderno::Contact.all
72
- assert_not_equal contacts_after.last.id, contact_id
73
- end
74
- end
75
-
76
- should 'know the rate limit' do
77
- VCR.use_cassette('rate limit') do
78
- rate_limit_info = Quaderno::Base.rate_limit_info
79
- assert_operator rate_limit_info[:remaining], :< ,2000
80
- end
81
- end
82
- end
83
- end
@@ -1,104 +0,0 @@
1
- require 'helper'
2
-
3
- class TestQuadernoContactThreadSafe < Test::Unit::TestCase
4
- context 'using the thread-safe configuration' do
5
- context 'with an authentication token' do
6
- should 'get all contacts (populated db)' do
7
- VCR.use_cassette('all contacts by authentication token') do
8
- puts Quaderno::Base.url
9
- contacts = Quaderno::Contact.all(api_url: TEST_URL, auth_token: TEST_KEY)
10
- assert_not_nil contacts
11
- assert_kind_of Array, contacts
12
- contacts.each { |contact| assert_kind_of Quaderno::Contact, contact }
13
- end
14
- end
15
-
16
- should 'find a contact' do
17
- VCR.use_cassette('found contact by authentication token') do
18
- contacts = Quaderno::Contact.all(api_url: TEST_URL, auth_token: TEST_KEY)
19
- contact = Quaderno::Contact.find contacts[2].id, api_url: TEST_URL, auth_token: TEST_KEY
20
- assert_kind_of Quaderno::Contact, contact
21
- assert_equal contacts[2].id, contact.id
22
- end
23
- end
24
-
25
- should 'create a contact' do
26
- VCR.use_cassette('new contact by authentication token') do
27
- contact = Quaderno::Contact.create(kind: 'company', first_name: 'Test_Skynet', email: 'my_little@po.ny', api_url: TEST_URL, auth_token: TEST_KEY)
28
- assert_kind_of Quaderno::Contact, contact
29
- assert_equal 'company', contact.kind
30
- assert_equal 'Test_Skynet', contact.full_name
31
- end
32
- end
33
-
34
- should 'update a contact' do
35
- VCR.use_cassette('updated contact by authentication token') do
36
- contacts = Quaderno::Contact.all(api_url: TEST_URL, auth_token: TEST_KEY)
37
- contact = Quaderno::Contact.update(contacts[2].id, first_name: 'Test_OCP', email: 'dont@stop.believing', api_url: TEST_URL, auth_token: TEST_KEY)
38
- assert_kind_of Quaderno::Contact, contact
39
- assert_equal 'Test_OCP', contact.first_name || contact.full_name
40
- end
41
- end
42
-
43
- should 'delete a contact' do
44
- VCR.use_cassette('deleted contact by authentication token') do
45
- new_contact = Quaderno::Contact.create(kind: 'company', first_name: 'Z, Mazinger Z', email: 'koji@kabuto.ftw', api_url: TEST_URL, auth_token: TEST_KEY)
46
- contacts_before = Quaderno::Contact.all(api_url: TEST_URL, auth_token: TEST_KEY)
47
- contact_id = contacts_before.last.id
48
- Quaderno::Contact.delete contact_id, api_url: TEST_URL, auth_token: TEST_KEY
49
- contacts_after = Quaderno::Contact.all(api_url: TEST_URL, auth_token: TEST_KEY)
50
- assert_not_equal contacts_after.last.id, contact_id
51
- end
52
- end
53
- end
54
-
55
- context 'with an OAuth 2.0 access token' do
56
- should 'get all contacts (populated db)' do
57
- VCR.use_cassette('all contacts by access token') do
58
- contacts = Quaderno::Contact.all(api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
59
- assert_not_nil contacts
60
- assert_kind_of Array, contacts
61
- contacts.each { |contact| assert_kind_of Quaderno::Contact, contact }
62
- end
63
- end
64
-
65
- should 'find a contact' do
66
- VCR.use_cassette('found contact by access token') do
67
- contacts = Quaderno::Contact.all(api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
68
- contact = Quaderno::Contact.find contacts[2].id, api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN
69
- assert_kind_of Quaderno::Contact, contact
70
- assert_equal contacts[2].id, contact.id
71
- end
72
- end
73
-
74
- should 'create a contact' do
75
- VCR.use_cassette('new contact by access token') do
76
- contact = Quaderno::Contact.create(kind: 'company', first_name: 'Test_Skynet', email: 'my_little@po.ny', api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
77
- assert_kind_of Quaderno::Contact, contact
78
- assert_equal 'company', contact.kind
79
- assert_equal 'Test_Skynet', contact.full_name
80
- end
81
- end
82
-
83
- should 'update a contact' do
84
- VCR.use_cassette('updated contact by access token') do
85
- contacts = Quaderno::Contact.all(api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
86
- contact = Quaderno::Contact.update(contacts[2].id, first_name: 'Test_OCP', email: 'dont@stop.believing', api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
87
- assert_kind_of Quaderno::Contact, contact
88
- assert_equal 'Test_OCP', contact.first_name || contact.full_name
89
- end
90
- end
91
-
92
- should 'delete a contact' do
93
- VCR.use_cassette('deleted contact by access token') do
94
- new_contact = Quaderno::Contact.create(kind: 'company', first_name: 'Z, Mazinger Z', email: 'koji@kabuto.ftw', api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
95
- contacts_before = Quaderno::Contact.all(api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
96
- contact_id = contacts_before.last.id
97
- Quaderno::Contact.delete contact_id, api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN
98
- contacts_after = Quaderno::Contact.all(api_url: TEST_URL, access_token: TEST_OAUTH_ACCESS_TOKEN)
99
- assert_not_equal contacts_after.last.id, contact_id
100
- end
101
- end
102
- end
103
- end
104
- end