jimmyz-fs-familytree-v1 0.1.0 → 0.2.1

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/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 1
3
- :patch: 0
2
+ :minor: 2
3
+ :patch: 1
4
4
  :major: 0
@@ -0,0 +1,33 @@
1
+ require 'fs_communicator'
2
+
3
+ module FsFamilytreeV1
4
+
5
+ # This method gets mixed into the FsCommunicator so that
6
+ # you can make calls on the fs_familytree_v1 module
7
+ def fs_familytree_v1
8
+ @com ||= Communicator.new self # self at this point refers to the FsCommunicator instance
9
+ end
10
+
11
+ class Communicator
12
+ Base = '/familytree/v1/'
13
+
14
+ # ==params
15
+ # fs_communicator: FsCommunicator instance
16
+ def initialize(fs_communicator)
17
+ @fs_communicator = fs_communicator
18
+ end
19
+
20
+ def person(id, options = {})
21
+ url = Base + 'person/' + id
22
+ response = @fs_communicator.get(url)
23
+ familytree = Familytree.parse response.body
24
+ person = familytree.persons.person.find{|p| p.requestedId == id }
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ # Mix in the module so that the fs_familytree_v1 can be called
31
+ class FsCommunicator
32
+ include FsFamilytreeV1
33
+ end
@@ -1,12 +1,19 @@
1
+ dir = File.dirname(__FILE__)
2
+ $:.unshift(dir) unless $:.include?(dir) || $:.include?(File.expand_path(dir))
3
+
1
4
  require 'rubygems'
2
5
  gem 'jimmyz-happymapper'
3
6
  require 'happymapper'
4
7
 
5
- module FsFamilytreeV1
8
+ require 'communicator'
6
9
 
10
+ module FsFamilytreeV1
11
+ NS = 'http://api.familysearch.org/familytree/v1'
12
+
7
13
  class AlternateIds
8
14
  include HappyMapper
9
15
 
16
+ namespace_url NS
10
17
  tag :alternateIds
11
18
  has_many :id, String
12
19
  end
@@ -14,6 +21,7 @@ module FsFamilytreeV1
14
21
  class PersonInformation
15
22
  include HappyMapper
16
23
 
24
+ namespace_url NS
17
25
  tag :information
18
26
  element :gender, String
19
27
  element :living, Boolean
@@ -23,6 +31,7 @@ module FsFamilytreeV1
23
31
  class NamePiece
24
32
  include HappyMapper
25
33
 
34
+ namespace_url NS
26
35
  tag :piece
27
36
  attribute :type, String
28
37
  element :value, String
@@ -31,12 +40,14 @@ module FsFamilytreeV1
31
40
  class Pieces
32
41
  include HappyMapper
33
42
 
43
+ namespace_url NS
34
44
  has_many :piece, NamePiece
35
45
  end
36
46
 
37
47
  class NameForm
38
48
  include HappyMapper
39
49
 
50
+ namespace_url NS
40
51
  tag :form
41
52
  element :fullText, String
42
53
  has_one :pieces, Pieces
@@ -46,6 +57,7 @@ module FsFamilytreeV1
46
57
  class Forms
47
58
  include HappyMapper
48
59
 
60
+ namespace_url NS
49
61
  has_many :form, NameForm
50
62
  end
51
63
 
@@ -53,6 +65,7 @@ module FsFamilytreeV1
53
65
  def self.init(options = {})
54
66
  include HappyMapper
55
67
 
68
+ namespace_url NS
56
69
  attribute :id, String
57
70
  attribute :version, String
58
71
  attribute :submitter, String
@@ -80,6 +93,7 @@ module FsFamilytreeV1
80
93
  class DateAstro
81
94
  include HappyMapper
82
95
 
96
+ namespace_url NS
83
97
  tag :astro
84
98
  element :earliest, Integer
85
99
  element :latest, Integer
@@ -88,6 +102,7 @@ module FsFamilytreeV1
88
102
  class Date
89
103
  include HappyMapper
90
104
 
105
+ namespace_url NS
91
106
  element :original, String
92
107
  element :normalized, String
93
108
  element :astro, DateAstro
@@ -96,6 +111,7 @@ module FsFamilytreeV1
96
111
  class Place
97
112
  include HappyMapper
98
113
 
114
+ namespace_url NS
99
115
  element :original, String
100
116
  element :normalized, String, :attributes => {:placeId => String}
101
117
  end
@@ -104,6 +120,7 @@ module FsFamilytreeV1
104
120
  def self.init
105
121
  include HappyMapper
106
122
 
123
+ namespace_url NS
107
124
  attribute :role, String
108
125
  attribute :ref, String
109
126
  attribute :tempId, String
@@ -158,6 +175,7 @@ module FsFamilytreeV1
158
175
  class Assertions
159
176
  include HappyMapper
160
177
 
178
+ namespace_url NS
161
179
  has_many :name, Name
162
180
  has_many :gender, Gender
163
181
  has_many :event, Event
@@ -168,6 +186,7 @@ module FsFamilytreeV1
168
186
  class Person
169
187
  include HappyMapper
170
188
 
189
+ namespace_url NS
171
190
  attribute :id, String
172
191
  attribute :requestedId, String
173
192
  attribute :version, String
@@ -179,12 +198,14 @@ module FsFamilytreeV1
179
198
  class Persons
180
199
  include HappyMapper
181
200
 
201
+ namespace_url NS
182
202
  has_many :person, Person
183
203
  end
184
204
 
185
205
  class Familytree
186
206
  include HappyMapper
187
207
 
208
+ namespace_url NS
188
209
  attribute :version, String
189
210
  attribute :statusMessage, String
190
211
  attribute :statusCode, Integer
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe FsFamilytreeV1::Communicator do
4
+
5
+ describe "fs_familytree_v1 call on the FsCommunicator" do
6
+ before(:each) do
7
+ @com = FsCommunicator.new
8
+ @ft_com_mock = mock("FsFamilytreeV1::Communicator")
9
+ end
10
+
11
+ it "should add an fs_familytree_v1 method to the communicator" do
12
+ @com.should respond_to(:fs_familytree_v1)
13
+ end
14
+
15
+ it "should return a Communicator object when called" do
16
+ FsFamilytreeV1::Communicator.should_receive(:new).with(@com).and_return(@ft_com_mock)
17
+ famtree_com = @com.fs_familytree_v1
18
+ famtree_com.should == @ft_com_mock
19
+ end
20
+ end
21
+
22
+ describe "person read" do
23
+ before(:each) do
24
+ @fs_com_mock = mock("FsCommunicator")
25
+ @res = mock("HTTP::Response")
26
+ @xml = fixture_file('person/KJ86-3VD.xml')
27
+ @res.stub!(:body).and_return(@xml)
28
+ @fs_com_mock.stub!(:get).and_return(@res)
29
+
30
+ @ft_v1_com = FsFamilytreeV1::Communicator.new @fs_com_mock
31
+ end
32
+
33
+ it "should call get on the FsCommunicator" do
34
+ @fs_com_mock.should_receive(:get).with('/familytree/v1/person/KJ86-3VD').and_return(@res)
35
+ @ft_v1_com.person('KJ86-3VD')
36
+ end
37
+
38
+ it "should parse the result body from the call" do
39
+ ft = FsFamilytreeV1::Familytree.parse(@xml)
40
+ FsFamilytreeV1::Familytree.should_receive(:parse).with(@xml).and_return(ft)
41
+ @ft_v1_com.person('KJ86-3VD')
42
+ end
43
+
44
+ it "should return a person of the id requested" do
45
+ id = 'KJ86-3VD'
46
+ person = @ft_v1_com.person(id)
47
+ person.id.should == id
48
+ end
49
+
50
+ end
51
+
52
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jimmyz-fs-familytree-v1
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Zimmerman
@@ -42,7 +42,9 @@ extra_rdoc_files: []
42
42
 
43
43
  files:
44
44
  - VERSION.yml
45
+ - lib/communicator.rb
45
46
  - lib/fs_familytree_v1.rb
47
+ - spec/communicator_spec.rb
46
48
  - spec/fixtures
47
49
  - spec/fixtures/person
48
50
  - spec/fixtures/person/KJ86-3VD.xml