ns_connector 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/Gemfile +13 -0
  2. data/Gemfile.lock +80 -0
  3. data/Guardfile +9 -0
  4. data/HACKING +31 -0
  5. data/LICENSE.txt +7 -0
  6. data/README.rdoc +191 -0
  7. data/Rakefile +45 -0
  8. data/VERSION +1 -0
  9. data/lib/ns_connector.rb +4 -0
  10. data/lib/ns_connector/attaching.rb +42 -0
  11. data/lib/ns_connector/chunked_searching.rb +111 -0
  12. data/lib/ns_connector/config.rb +66 -0
  13. data/lib/ns_connector/errors.rb +79 -0
  14. data/lib/ns_connector/field_store.rb +19 -0
  15. data/lib/ns_connector/hash.rb +11 -0
  16. data/lib/ns_connector/resource.rb +288 -0
  17. data/lib/ns_connector/resources.rb +3 -0
  18. data/lib/ns_connector/resources/contact.rb +279 -0
  19. data/lib/ns_connector/resources/customer.rb +355 -0
  20. data/lib/ns_connector/resources/invoice.rb +466 -0
  21. data/lib/ns_connector/restlet.rb +137 -0
  22. data/lib/ns_connector/sublist.rb +21 -0
  23. data/lib/ns_connector/sublist_item.rb +25 -0
  24. data/misc/failed_sublist_saving_patch +547 -0
  25. data/scripts/run_restlet +25 -0
  26. data/scripts/test_shell +21 -0
  27. data/spec/attaching_spec.rb +48 -0
  28. data/spec/chunked_searching_spec.rb +75 -0
  29. data/spec/config_spec.rb +43 -0
  30. data/spec/resource_spec.rb +340 -0
  31. data/spec/resources/contact_spec.rb +8 -0
  32. data/spec/resources/customer_spec.rb +8 -0
  33. data/spec/resources/invoice_spec.rb +20 -0
  34. data/spec/restlet_spec.rb +135 -0
  35. data/spec/spec_helper.rb +16 -0
  36. data/spec/sublist_item_spec.rb +25 -0
  37. data/spec/sublist_spec.rb +45 -0
  38. data/spec/support/mock_data.rb +10 -0
  39. data/support/read_only_test +63 -0
  40. data/support/restlet.js +384 -0
  41. data/support/super_dangerous_write_test +85 -0
  42. metadata +221 -0
@@ -0,0 +1,466 @@
1
+ require 'base64'
2
+ require 'ns_connector/resource'
3
+ # == Invoice resource
4
+ # === Fields
5
+ # * id
6
+ # * account
7
+ # * althandlingcost
8
+ # * altshippingcost
9
+ # * amountpaid
10
+ # * amountremaining
11
+ # * amountremainingtotalbox
12
+ # * balance
13
+ # * billaddr1
14
+ # * billaddr2
15
+ # * billaddr3
16
+ # * billaddress
17
+ # * billaddressee
18
+ # * billaddresslist
19
+ # * billattention
20
+ # * billcity
21
+ # * billcountry
22
+ # * billisresidential
23
+ # * billphone
24
+ # * billstate
25
+ # * billzip
26
+ # * consolidatebalance
27
+ # * couponcode
28
+ # * createddate
29
+ # * createdfrom
30
+ # * currency
31
+ # * currencyname
32
+ # * currencysymbol
33
+ # * customform
34
+ # * deferredrevenue
35
+ # * department
36
+ # * discountamount
37
+ # * discountdate
38
+ # * discountitem
39
+ # * discountrate
40
+ # * discounttotal
41
+ # * duedate
42
+ # * email
43
+ # * enddate
44
+ # * entity
45
+ # * entitynexus
46
+ # * estgrossprofit
47
+ # * estgrossprofitpercent
48
+ # * exchangerate
49
+ # * excludecommission
50
+ # * expcostdiscamount
51
+ # * expcostdiscount
52
+ # * expcostdiscprint
53
+ # * expcostdiscrate
54
+ # * expcostdisctaxable
55
+ # * expcosttaxcode
56
+ # * expcosttaxrate1
57
+ # * externalid
58
+ # * fob
59
+ # * giftcertapplied
60
+ # * handlingcost
61
+ # * handlingtax1rate
62
+ # * handlingtaxcode
63
+ # * isbasecurrency
64
+ # * ismultishipto
65
+ # * istaxable
66
+ # * itemcostdiscamount
67
+ # * itemcostdiscount
68
+ # * itemcostdiscprint
69
+ # * itemcostdiscrate
70
+ # * itemcostdisctaxable
71
+ # * itemcosttaxcode
72
+ # * itemcosttaxrate1
73
+ # * lastmodifieddate
74
+ # * leadsource
75
+ # * attachedtrackingnumbers
76
+ # * location
77
+ # * memo
78
+ # * message
79
+ # * messagesel
80
+ # * muccpromocodeinstance
81
+ # * nexus
82
+ # * opportunity
83
+ # * otherrefnum
84
+ # * partner
85
+ # * postingperiod
86
+ # * promocode
87
+ # * promocodepluginimpl
88
+ # * recognizedrevenue
89
+ # * returntrackingnumbers
90
+ # * revenuestatus
91
+ # * revreconrevcommitment
92
+ # * saleseffectivedate
93
+ # * salesgroup
94
+ # * salesrep
95
+ # * shipaddr1
96
+ # * shipaddr2
97
+ # * shipaddr3
98
+ # * shipaddress
99
+ # * shipaddressee
100
+ # * shipaddresslist
101
+ # * shipattention
102
+ # * shipcity
103
+ # * shipcountry
104
+ # * shipdate
105
+ # * shipisresidential
106
+ # * shipmethod
107
+ # * shipoverride
108
+ # * shipphone
109
+ # * shippingcost
110
+ # * shippingcostoverridden
111
+ # * shippingtax1rate
112
+ # * shippingtaxcode
113
+ # * shipstate
114
+ # * shipzip
115
+ # * source
116
+ # * startdate
117
+ # * status
118
+ # * statusRef
119
+ # * subsidiary
120
+ # * subtotal
121
+ # * syncpartnerteams
122
+ # * syncsalesteams
123
+ # * taxitem
124
+ # * taxrate
125
+ # * taxtotal
126
+ # * terms
127
+ # * timediscamount
128
+ # * timediscount
129
+ # * timediscprint
130
+ # * timediscrate
131
+ # * timedisctaxable
132
+ # * timetaxcode
133
+ # * timetaxrate1
134
+ # * tobeemailed
135
+ # * tobefaxed
136
+ # * tobeprinted
137
+ # * total
138
+ # * totalcostestimate
139
+ # * trackingnumbers
140
+ # * trandate
141
+ # * tranid
142
+ # * tranisvsoebundle
143
+ # * unbilledorders
144
+ # * vsoeautocalc
145
+ # === SubLists
146
+ # * expcost
147
+ # * item
148
+ # * itemcost
149
+ # * partners
150
+ # * salesteam
151
+ # * shipgroup
152
+ # * time
153
+
154
+ class NSConnector::Invoice < NSConnector::Resource
155
+ @type_id = 'invoice'
156
+ @fields = [
157
+ :id,
158
+ :account,
159
+ :althandlingcost,
160
+ :altshippingcost,
161
+ :amountpaid,
162
+ :amountremaining,
163
+ :amountremainingtotalbox,
164
+ :balance,
165
+ :billaddr1,
166
+ :billaddr2,
167
+ :billaddr3,
168
+ :billaddress,
169
+ :billaddressee,
170
+ :billaddresslist,
171
+ :billattention,
172
+ :billcity,
173
+ :billcountry,
174
+ :billisresidential,
175
+ :billphone,
176
+ :billstate,
177
+ :billzip,
178
+ :consolidatebalance,
179
+ :couponcode,
180
+ :createddate,
181
+ :createdfrom,
182
+ :currency,
183
+ :currencyname,
184
+ :currencysymbol,
185
+ :customform,
186
+ :deferredrevenue,
187
+ :department,
188
+ :discountamount,
189
+ :discountdate,
190
+ :discountitem,
191
+ :discountrate,
192
+ :discounttotal,
193
+ :duedate,
194
+ :email,
195
+ :enddate,
196
+ :entity,
197
+ :entitynexus,
198
+ :estgrossprofit,
199
+ :estgrossprofitpercent,
200
+ :exchangerate,
201
+ :excludecommission,
202
+ :expcostdiscamount,
203
+ :expcostdiscount,
204
+ :expcostdiscprint,
205
+ :expcostdiscrate,
206
+ :expcostdisctaxable,
207
+ :expcosttaxcode,
208
+ :expcosttaxrate1,
209
+ :externalid,
210
+ :fob,
211
+ :giftcertapplied,
212
+ :handlingcost,
213
+ :handlingtax1rate,
214
+ :handlingtaxcode,
215
+ :isbasecurrency,
216
+ :ismultishipto,
217
+ :istaxable,
218
+ :itemcostdiscamount,
219
+ :itemcostdiscount,
220
+ :itemcostdiscprint,
221
+ :itemcostdiscrate,
222
+ :itemcostdisctaxable,
223
+ :itemcosttaxcode,
224
+ :itemcosttaxrate1,
225
+ :lastmodifieddate,
226
+ :leadsource,
227
+ :attachedtrackingnumbers,
228
+ :location,
229
+ :memo,
230
+ :message,
231
+ :messagesel,
232
+ :muccpromocodeinstance,
233
+ :nexus,
234
+ :opportunity,
235
+ :otherrefnum,
236
+ :partner,
237
+ :postingperiod,
238
+ :promocode,
239
+ :promocodepluginimpl,
240
+ :recognizedrevenue,
241
+ :returntrackingnumbers,
242
+ :revenuestatus,
243
+ :revreconrevcommitment,
244
+ :saleseffectivedate,
245
+ :salesgroup,
246
+ :salesrep,
247
+ :shipaddr1,
248
+ :shipaddr2,
249
+ :shipaddr3,
250
+ :shipaddress,
251
+ :shipaddressee,
252
+ :shipaddresslist,
253
+ :shipattention,
254
+ :shipcity,
255
+ :shipcountry,
256
+ :shipdate,
257
+ :shipisresidential,
258
+ :shipmethod,
259
+ :shipoverride,
260
+ :shipphone,
261
+ :shippingcost,
262
+ :shippingcostoverridden,
263
+ :shippingtax1rate,
264
+ :shippingtaxcode,
265
+ :shipstate,
266
+ :shipzip,
267
+ :source,
268
+ :startdate,
269
+ :status,
270
+ :statusRef,
271
+ :subsidiary,
272
+ :subtotal,
273
+ :syncpartnerteams,
274
+ :syncsalesteams,
275
+ :taxitem,
276
+ :taxrate,
277
+ :taxtotal,
278
+ :terms,
279
+ :timediscamount,
280
+ :timediscount,
281
+ :timediscprint,
282
+ :timediscrate,
283
+ :timedisctaxable,
284
+ :timetaxcode,
285
+ :timetaxrate1,
286
+ :tobeemailed,
287
+ :tobefaxed,
288
+ :tobeprinted,
289
+ :total,
290
+ :totalcostestimate,
291
+ :trackingnumbers,
292
+ :trandate,
293
+ :tranid,
294
+ :tranisvsoebundle,
295
+ :unbilledorders,
296
+ :vsoeautocalc,
297
+ ]
298
+ @sublists = {
299
+ :expcost => [
300
+ :amortizationperiod,
301
+ :amortizationtype,
302
+ :amount,
303
+ :apply,
304
+ :billeddate,
305
+ :category,
306
+ :doc,
307
+ :employee,
308
+ :job,
309
+ :line,
310
+ :location,
311
+ :memo,
312
+ :originalamount,
313
+ :revrecenddate,
314
+ :revrecschedule,
315
+ :revrecstartdate,
316
+ :taxable,
317
+ :taxcode,
318
+ :taxrate1,
319
+ :url,
320
+ ],
321
+ :item => [
322
+ :account,
323
+ :amortizationperiod,
324
+ :amortizationtype,
325
+ :amount,
326
+ :billvariancestatus,
327
+ :costestimate,
328
+ :costestimaterate,
329
+ :costestimatetype,
330
+ :daysbeforeexpiration,
331
+ :deferrevrec,
332
+ :description,
333
+ :giftcertfrom,
334
+ :giftcertmessage,
335
+ :giftcertrecipientemail,
336
+ :giftcertrecipientname,
337
+ :id,
338
+ :inventorydetail,
339
+ :istaxable,
340
+ :isvsoebundle,
341
+ :item,
342
+ :itemsubtype,
343
+ :itemtype,
344
+ :job,
345
+ :licensecode,
346
+ :line,
347
+ :linenumber,
348
+ :matrixtype,
349
+ :options,
350
+ :price,
351
+ :printitems,
352
+ :quantity,
353
+ :quantityavailable,
354
+ :quantityremaining,
355
+ :rate,
356
+ :rateschedule,
357
+ :revrecenddate,
358
+ :revrecschedule,
359
+ :revrecstartdate,
360
+ :shipaddress,
361
+ :shipcarrier,
362
+ :shipmethod,
363
+ :taxcode,
364
+ :taxrate1,
365
+ :units,
366
+ :vsoeallocation,
367
+ :vsoeamount,
368
+ :vsoedeferral,
369
+ :vsoedelivered,
370
+ :vsoeisestimate,
371
+ :vsoepermitdiscount,
372
+ :vsoeprice,
373
+ :vsoesopgroup,
374
+ ],
375
+ :itemcost => [
376
+ :amortizationperiod,
377
+ :amortizationtype,
378
+ :amount,
379
+ :apply,
380
+ :billeddate,
381
+ :binnumbers,
382
+ :cost,
383
+ :doc,
384
+ :item,
385
+ :itemcostcount,
386
+ :job,
387
+ :line,
388
+ :location,
389
+ :memo,
390
+ :options,
391
+ :rateschedule,
392
+ :revrecenddate,
393
+ :revrecschedule,
394
+ :revrecstartdate,
395
+ :serialnumbers,
396
+ :taxable,
397
+ :taxcode,
398
+ :taxrate1,
399
+ :unit,
400
+ :url,
401
+ ],
402
+ :partners => [
403
+ :contribution,
404
+ :id,
405
+ :isprimary,
406
+ :partner,
407
+ :partnerrole,
408
+ :transaction,
409
+ ],
410
+ :salesteam => [
411
+ :contribution,
412
+ :employee,
413
+ :id,
414
+ :isprimary,
415
+ :issalesrep,
416
+ :salesrole,
417
+ :transaction,
418
+ ],
419
+ :shipgroup => [
420
+ :destinationaddress,
421
+ :handlingrate,
422
+ :id,
423
+ :shippingcarrier,
424
+ :shippingmethod,
425
+ :shippingrate,
426
+ :sourceaddress,
427
+ :weight,
428
+ ],
429
+ :time => [
430
+ :amortizationperiod,
431
+ :amortizationtype,
432
+ :amount,
433
+ :apply,
434
+ :billeddate,
435
+ :doc,
436
+ :item,
437
+ :job,
438
+ :memo,
439
+ :rate,
440
+ :rateschedule,
441
+ :revrecenddate,
442
+ :revrecschedule,
443
+ :revrecstartdate,
444
+ :taxable,
445
+ :taxcode,
446
+ :taxrate1,
447
+ :unit,
448
+ :url,
449
+ ]
450
+ }
451
+
452
+ # Convert ourself to PDF
453
+ # Returns:: A long string with the PDF data
454
+ def to_pdf
455
+ unless id then raise ::ArgumentError,
456
+ 'Could not find id for this Invoice, are you trying '\
457
+ 'to convert an invoice to PDF without creating it?'
458
+ end
459
+
460
+ encoded = NSConnector::Restlet.execute!(
461
+ :action => 'invoice_pdf',
462
+ :invoice_id => id
463
+ ).first
464
+ Base64::decode64(encoded)
465
+ end
466
+ end