ruby-fs-stack 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -30,6 +30,7 @@ or for the pure Ruby implementation
30
30
 
31
31
  === Authenticating with FamilySearch
32
32
 
33
+ require 'rubygems'
33
34
  require 'ruby-fs-stack'
34
35
 
35
36
  communicator = FsCommunicator.new :domain => 'http://www.dev.usys.org', # or 'https://api.familysearch.org'
@@ -58,6 +59,10 @@ or for the pure Ruby implementation
58
59
  puts "First spouse's gender: " + person.families[0].parents[1].gender
59
60
  puts "First spouse's ID: " + person.families[0].parents[1].id
60
61
 
62
+ # read multiple persons in one request (up to 10)
63
+ people = ftcom.person ['KW3B-NNM','KWQS-BBQ','KWQS-BBR'], :parents => 'all', :children => 'all', :families => 'all'
64
+ people.size #=> 3
65
+
61
66
  === Searching Records
62
67
 
63
68
  search = communicator.familytree_v2.search :givenName => "John",
@@ -78,7 +83,20 @@ or for the pure Ruby implementation
78
83
  puts result.mother.full_name #=> "Ruby Johnson"
79
84
  puts result.spouses.first.full_name #=> "Sarah Franklin"
80
85
  end
86
+
87
+ === Combining Records
88
+
89
+ # reads the latest version numbers for the people requested and POSTs a combine request.
90
+ new_person = communicator.familytree_v2.combine ['KWQS-BBQ','KWRS-BBZ','KWQS-BNR']
91
+ new_person.id #=> 'KWQS-ZZZ'
92
+ new_person.version #=> '687799'
81
93
 
94
+ == RDoc
95
+
96
+ RDoc is hosted at rdoc.info:
97
+
98
+ http://rdoc.info/projects/jimmyz/ruby-fs-stack
99
+
82
100
  == Discussion
83
101
 
84
102
  A Google Group has been set up for questions and discussion
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
@@ -0,0 +1,74 @@
1
+
2
+ module RubyFsStack
3
+ class FamilySearchError < StandardError
4
+ attr_reader :communicator
5
+ def initialize(msg = nil, communicator = nil)
6
+ @communicator = communicator if communicator
7
+ super(msg)
8
+ end
9
+ end
10
+
11
+ # 310 The user needs to go to the family tree and perform
12
+ # some action, such as read a new version of the conditions of use.
13
+ class UserActionRequired < FamilySearchError
14
+ end
15
+
16
+ # 400 Bad Request. Generic client error or multiple client errors.
17
+ class BadRequest < FamilySearchError
18
+ end
19
+
20
+ # 401 Unauthorized. The user has invalid credentials or the session
21
+ # ID is missing, invalid, or has expired. This error also appears if
22
+ # the query string contains multiple question marks or the the session
23
+ # parameter contains letters in an incorrect case.
24
+ class Unauthorized < FamilySearchError
25
+ end
26
+
27
+ # 403 Forbidden. The user does not have sufficient rights to perform
28
+ # the operation.
29
+ class Forbidden < FamilySearchError
30
+ end
31
+
32
+ # 404 Not Found. This request contained an invalid ID or a bad URI.
33
+ class NotFound < FamilySearchError
34
+ end
35
+
36
+ # 409 Conflict. The action could not be performed because it would
37
+ # create a conflict.
38
+ class Conflict < FamilySearchError
39
+ end
40
+
41
+ # 410 Gone. The requested resource has been deleted or recanted OR the
42
+ # requested version of the API has been retired.
43
+ class Gone < FamilySearchError
44
+ end
45
+
46
+ # 415 Unsupported media type, invalid content-type in header, or invalid
47
+ # character encoding.
48
+ class InvalidContentType < FamilySearchError
49
+ end
50
+
51
+ # 430 Bad version. Incorrect version of the object.
52
+ class BadVersion < FamilySearchError
53
+ end
54
+
55
+ # 431 Invalid developer key.
56
+ class InvalidDeveloperKey < FamilySearchError
57
+ end
58
+
59
+ # 500 Server Error. A generic server error or multiple server errors
60
+ # occurred. If you get this error, please report it at https://issues.devnet.familysearch.org.
61
+ class ServerError < FamilySearchError
62
+ end
63
+
64
+ # 501 Not Implemented. The requested service or combination of parameters
65
+ # has not been implemented.
66
+ class NotImplemented < FamilySearchError
67
+ end
68
+
69
+ # 503 Service Unavailable. FamilySearch or the service that you are using is not currently
70
+ # available. Or you are being throttled.
71
+ class ServiceUnavailable < FamilySearchError
72
+ end
73
+
74
+ end
@@ -1,9 +1,10 @@
1
+ require 'ruby-fs-stack/errors'
1
2
  require 'net/https'
2
3
  require 'uri'
3
4
 
4
5
  class FsCommunicator
5
6
  attr_accessor :domain, :key, :user_agent, :session, :handle_throttling
6
-
7
+ include RubyFsStack
7
8
  # ====Params
8
9
  # <tt>options</tt> - a hash with the following options
9
10
  # * :domain - Defaults to "http://www.dev.usys.org" (the Reference System)
@@ -75,11 +76,59 @@ class FsCommunicator
75
76
  if res.code == '503' && @handle_throttling
76
77
  sleep 15
77
78
  res = get(url,credentials)
79
+ elsif res.code != '200'
80
+ raise_exception(res)
78
81
  end
79
82
  return res
80
83
  end
81
84
 
82
85
  private
86
+
87
+ # 310 UserActionRequired
88
+ # 400 BadRequest
89
+ # 401 Unauthorized
90
+ # 403 Forbidden
91
+ # 404 NotFound
92
+ # 409 Conflict
93
+ # 410 Gone
94
+ # 415 InvalidContentType
95
+ # 430 BadVersion
96
+ # 431 InvalidDeveloperKey
97
+ # 500 ServerError
98
+ # 501 NotImplemented
99
+ # 503 ServiceUnavailable
100
+ def raise_exception(res)
101
+ case res.code
102
+ when "310"
103
+ exception = UserActionRequired.new res.message, self
104
+ when "400"
105
+ exception = BadRequest.new res.message, self
106
+ when "401"
107
+ exception = Unauthorized.new res.message, self
108
+ when "403"
109
+ exception = Forbidden.new res.message, self
110
+ when "404"
111
+ exception = NotFound.new res.message, self
112
+ when "409"
113
+ exception = Conflict.new res.message, self
114
+ when "410"
115
+ exception = Gone.new res.message, self
116
+ when "415"
117
+ exception = InvalidContentType.new res.message, self
118
+ when "430"
119
+ exception = BadVersion.new res.message, self
120
+ when "431"
121
+ exception = InvalidDeveloperKey.new res.message, self
122
+ when "500"
123
+ exception = ServerError.new res.message, self
124
+ when "501"
125
+ exception = NotImplemented.new res.message, self
126
+ when "503"
127
+ exception = ServiceUnavailable.new res.message, self
128
+ end
129
+ raise exception
130
+ end
131
+
83
132
  def set_extra_params(uri,credentials = {})
84
133
  if credentials[:username] && credentials[:password]
85
134
  sessionized_url = add_key(uri)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-fs-stack}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jimmy Zimmerman"]
12
- s.date = %q{2009-12-14}
12
+ s.date = %q{2009-12-16}
13
13
  s.description = %q{A library that enables you to read and update information with the new.familysearch.org API.}
14
14
  s.email = %q{jimmy.zimmerman@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "lib/ruby-fs-stack/enunciate/README",
32
32
  "lib/ruby-fs-stack/enunciate/familytree.rb",
33
33
  "lib/ruby-fs-stack/enunciate/identity.rb",
34
+ "lib/ruby-fs-stack/errors.rb",
34
35
  "lib/ruby-fs-stack/familytree.rb",
35
36
  "lib/ruby-fs-stack/fs_communicator.rb",
36
37
  "lib/ruby-fs-stack/fs_utils.rb",
@@ -1,5 +1,6 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
2
  require 'ruby-fs-stack/fs_communicator'
3
+ require 'fakeweb'
3
4
 
4
5
  describe FsCommunicator do
5
6
  include HttpCommunicatorHelper
@@ -211,4 +212,127 @@ describe FsCommunicator do
211
212
 
212
213
  end
213
214
 
215
+ # 310 UserActionRequired
216
+ # 400 BadRequest
217
+ # 401 Unauthorized
218
+ # 403 Forbidden
219
+ # 404 NotFound
220
+ # 409 Conflict
221
+ # 410 Gone
222
+ # 415 InvalidContentType
223
+ # 430 BadVersion
224
+ # 431 InvalidDeveloperKey
225
+ # 500 ServerError
226
+ # 501 NotImplemented
227
+ # 503 ServiceUnavailable
228
+ describe "raising exceptions" do
229
+ def fake_web(path,status,message)
230
+ FakeWeb.register_uri(:get, "https://api.familysearch.org#{path}?sessionId=SESSID&dataFormat=application/json", :body => "",
231
+ :status => [status, message])
232
+ end
233
+
234
+ before(:each) do
235
+ options = {
236
+ :domain => 'https://api.familysearch.org',
237
+ :key => '1111-1111',
238
+ :user_agent => "FsCommunicator/0.1",
239
+ :session => 'SESSID'
240
+ }
241
+ @com = FsCommunicator.new options
242
+ @path = '/familytree/v2/person'
243
+ FakeWeb.allow_net_connect = false
244
+ end
245
+
246
+ it "should raise a UserActionRequired on a 310" do
247
+ fake_web(@path,'310',"User Action Required")
248
+ lambda{
249
+ @com.get(@path)
250
+ }.should raise_error(RubyFsStack::UserActionRequired)
251
+ end
252
+
253
+ it "should raise a BadRequest on a 400" do
254
+ fake_web(@path,'400',"Bad Request")
255
+ lambda{
256
+ @com.get(@path)
257
+ }.should raise_error(RubyFsStack::BadRequest)
258
+ end
259
+
260
+ it "should raise a BadRequest on a 401" do
261
+ fake_web(@path,'401',"Unauthorized")
262
+ lambda{
263
+ @com.get(@path)
264
+ }.should raise_error(RubyFsStack::Unauthorized)
265
+ end
266
+
267
+ it "should raise a Forbidden on 403" do
268
+ fake_web(@path,'403',"Forbidden")
269
+ lambda{
270
+ @com.get(@path)
271
+ }.should raise_error(RubyFsStack::Forbidden)
272
+ end
273
+
274
+ it "should raise a 404 NotFound" do
275
+ fake_web(@path,'404',"NotFound")
276
+ lambda{
277
+ @com.get(@path)
278
+ }.should raise_error(RubyFsStack::NotFound)
279
+ end
280
+
281
+ it "should raise a 409 Conflict" do
282
+ fake_web(@path,'409',"Conflict")
283
+ lambda{
284
+ @com.get(@path)
285
+ }.should raise_error(RubyFsStack::Conflict)
286
+ end
287
+
288
+ it "should raise a 410 Gone" do
289
+ fake_web(@path,'410',"Gone")
290
+ lambda{
291
+ @com.get(@path)
292
+ }.should raise_error(RubyFsStack::Gone)
293
+ end
294
+
295
+ it "should raise a 415 InvalidContentType" do
296
+ fake_web(@path,'415',"Invalid Content Type")
297
+ lambda{
298
+ @com.get(@path)
299
+ }.should raise_error(RubyFsStack::InvalidContentType)
300
+ end
301
+
302
+ it "should raise a 430 BadVersion" do
303
+ fake_web(@path,'430',"Bad Version")
304
+ lambda{
305
+ @com.get(@path)
306
+ }.should raise_error(RubyFsStack::BadVersion)
307
+ end
308
+
309
+ it "should raise a 431 InvalidDeveloperKey" do
310
+ fake_web(@path,'431',"Invalid Developer Key")
311
+ lambda{
312
+ @com.get(@path)
313
+ }.should raise_error(RubyFsStack::InvalidDeveloperKey)
314
+ end
315
+
316
+ it "should raise a 500 ServerError" do
317
+ fake_web(@path,'500',"Server Error")
318
+ lambda{
319
+ @com.get(@path)
320
+ }.should raise_error(RubyFsStack::ServerError)
321
+ end
322
+
323
+ it "should raise a 501 NotImplemented" do
324
+ fake_web(@path,'501',"Not Implemented")
325
+ lambda{
326
+ @com.get(@path)
327
+ }.should raise_error(RubyFsStack::NotImplemented)
328
+ end
329
+
330
+ it "should raise a 503 ServiceUnavailable" do
331
+ fake_web(@path,'503',"Service Unavailable")
332
+ lambda{
333
+ @com.get(@path)
334
+ }.should raise_error(RubyFsStack::ServiceUnavailable)
335
+ end
336
+ end
337
+
214
338
  end
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
  require 'ruby-fs-stack/familytree'
3
3
 
4
4
  describe Org::Familysearch::Ws::Familytree::V2::Schema::MatchResults, "parsing match results" do
5
- FamilyTreeV2 = Org::Familysearch::Ws::Familytree::V2::Schema
5
+ FamilyTreeV2 = Org::Familysearch::Ws::Familytree::V2::Schema unless Object.const_defined?(:FamilyTreeV2)
6
6
 
7
7
  def read_file(filename)
8
8
  fname = File.join(File.dirname(__FILE__),'json',filename)
@@ -3,7 +3,7 @@ require 'ruby-fs-stack/familytree'
3
3
 
4
4
 
5
5
  describe Org::Familysearch::Ws::Familytree::V2::Schema::SearchResults do
6
- FamilyTreeV2 = Org::Familysearch::Ws::Familytree::V2::Schema
6
+ FamilyTreeV2 = Org::Familysearch::Ws::Familytree::V2::Schema unless Object.const_defined?(:FamilyTreeV2)
7
7
 
8
8
  def read_file(filename)
9
9
  fname = File.join(File.dirname(__FILE__),'json',filename)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-fs-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Zimmerman
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-14 00:00:00 -07:00
12
+ date: 2009-12-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -56,6 +56,7 @@ files:
56
56
  - lib/ruby-fs-stack/enunciate/README
57
57
  - lib/ruby-fs-stack/enunciate/familytree.rb
58
58
  - lib/ruby-fs-stack/enunciate/identity.rb
59
+ - lib/ruby-fs-stack/errors.rb
59
60
  - lib/ruby-fs-stack/familytree.rb
60
61
  - lib/ruby-fs-stack/fs_communicator.rb
61
62
  - lib/ruby-fs-stack/fs_utils.rb