ns_connector 0.0.11 → 0.0.12

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.
@@ -21,7 +21,6 @@ Avaliable at {rubydoc.info}[http://rubydoc.info/gems/ns_connector/0.0.10]
21
21
  * Read write for supported types
22
22
  * Flexible searching
23
23
  * Multithreaded chunked searching for retrieving large datasets
24
- * ActiveRecord (vaguely) alike interface
25
24
  * Read only sublist support.
26
25
  * SubList item creation on creating new records only. (>= v0.0.7)
27
26
  * Attaching and detaching records
@@ -114,20 +113,20 @@ Example:
114
113
 
115
114
  SubLists can be added to a record on creation. Here is how that works:
116
115
 
117
- include NSConnector
118
- c = Contact.new(:firstname => 'name')
119
- c.sublists
120
- => {:addressbook=>
121
- [:addr1,
122
- ...
123
-
124
- c.addressbook << c.new_addressbook_item({
125
- :addr1 => 'address line 1',
126
- :city => 'unicorn valley'
127
- })
116
+ include NSConnector
117
+ c = Contact.new(:firstname => 'name')
118
+ c.sublists
119
+ => {:addressbook=>
120
+ [:addr1,
121
+ ...
122
+
123
+ c.addressbook << c.new_addressbook_item({
124
+ :addr1 => 'address line 1',
125
+ :city => 'unicorn valley'
126
+ })
128
127
 
129
- c.save!
130
- => true
128
+ c.save!
129
+ => true
131
130
 
132
131
  === Reading
133
132
  You can find by any field or by internalId.
@@ -143,6 +142,10 @@ Example:
143
142
  Contact.find(12)
144
143
  => <#NSConnector::Contact:12>
145
144
 
145
+ # Fetch one Customer by entityid
146
+ Customer.find_by('entityid', 1234)
147
+ => <#NSConnector::Contact:12>
148
+
146
149
  # Fetch all Contacts, this will take a while. (Request will be broken
147
150
  # up into smaller ones and spread across multiple threads).
148
151
  Contact.all
@@ -205,6 +208,14 @@ e.g.
205
208
  "allowemptycards"=>nil,
206
209
  "applied"=>"99.99" ...
207
210
 
211
+ == Attaching records
212
+ You can attach/detach records with #attach! and #detach!, it's pretty simple.
213
+
214
+ # Attach customer 123 to contacts 1, 2 and 3 with the role of 1
215
+ Customer.find(123).attach!(Contact, [1,2,3], :role => 1)
216
+
217
+ # Or anonymously like:
218
+ Customer.attach!(Contact, 123, [1,2,3], :role => 1)
208
219
 
209
220
  === Troubleshooting note:
210
221
  Should you run into an error something like:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.0.12
@@ -6,20 +6,20 @@ module NSConnector::Errors
6
6
  # Parent class to encapsulate all successfully parsed JSON netsuite
7
7
  # error responses.
8
8
  class NSError < Exception
9
- def initialize netsuite_error
10
- @netsuite_error = netsuite_error
9
+ def initialize netsuite_error=nil
10
+ @netsuite_error = netsuite_error if netsuite_error
11
11
  end
12
12
 
13
13
  # Returns the error code from the JSON returned by netsuite.
14
14
  # Something like: "RCRD_DSNT_EXIST"
15
15
  def code
16
- @netsuite_error['code']
16
+ @netsuite_error['code'] rescue nil
17
17
  end
18
18
 
19
19
  # Takes the error message straight out of the netsuite
20
20
  # response. Usually makes some sense.
21
21
  def message
22
- @netsuite_error['message']
22
+ @netsuite_error['message'] rescue nil
23
23
  end
24
24
  end
25
25
 
@@ -197,6 +197,18 @@ class NSConnector::Resource
197
197
  )
198
198
  end
199
199
 
200
+ # Return a single resource, by searching for the given field.
201
+ # Returns:: A single record
202
+ # Raises:: NSConnector::Errors::NotFound when nothing found
203
+ def find_by(field, value)
204
+ results = search_by(field, value)
205
+ unless results.empty? then
206
+ return results.first
207
+ else
208
+ raise NSConnector::Errors::NotFound
209
+ end
210
+ end
211
+
200
212
  # Retrieve all records, will most likely become a chunked
201
213
  # search due to size
202
214
  def all
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ns_connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-01 00:00:00.000000000 Z
12
+ date: 2013-07-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -210,7 +210,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
210
210
  version: '0'
211
211
  segments:
212
212
  - 0
213
- hash: 1654202155437551994
213
+ hash: -1969978753903346248
214
214
  required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  none: false
216
216
  requirements: