ruby-fs-stack 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/jimmyz/ruby-fs-stack"
12
12
  gem.authors = ["Jimmy Zimmerman"]
13
13
  gem.add_development_dependency "rspec"
14
+ gem.add_development_dependency "fakeweb"
14
15
  gem.requirements << "This gem requires a json gem (json, json_pure, or json-jruby)."
15
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -80,6 +80,30 @@ module FamilytreeV2
80
80
  familytree.searches[0]
81
81
  end
82
82
 
83
+ # ====Params
84
+ # <tt>id_or_hash</tt> - Either an ID or a hash of match parameters matching API doc
85
+ # <tt>hash</tt> - if the first parameter is an ID, then this will contain the hash
86
+ # of match parameters.
87
+ def match(id_or_hash, hash={})
88
+ url = Base + 'match'
89
+ if id_or_hash.kind_of? String
90
+ id = id_or_hash
91
+ url += "/#{id}"
92
+ params_hash = hash
93
+ elsif id_or_hash.kind_of? Hash
94
+ id = nil
95
+ params_hash = id_or_hash
96
+ else
97
+ raise ArgumentError, "first parameter must be a kind of String or Hash"
98
+ end
99
+ url += "?" + FsUtils.querystring_from_hash(params_hash) unless params_hash.empty?
100
+ response = @fs_communicator.get(url)
101
+ familytree = Org::Familysearch::Ws::Familytree::V2::Schema::FamilyTree.from_json JSON.parse(response.body)
102
+ # require 'pp'
103
+ # pp familytree
104
+ familytree.matches[0]
105
+ end
106
+
83
107
  # ====Params
84
108
  # * <tt>base_id</tt> - The root person for creating the relationship
85
109
  # * <tt>options</tt> - Should include either :parent, :spouse, or :child. :lineage and :event is optional
@@ -807,6 +831,7 @@ module Org::Familysearch::Ws::Familytree::V2::Schema
807
831
 
808
832
  class SearchPerson
809
833
  alias :name :full_name
834
+ alias :ref :id
810
835
  def events
811
836
  (assertions && assertions.events) ? assertions.events : []
812
837
  end
@@ -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.1"
8
+ s.version = "0.2.2"
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-09}
12
+ s.date = %q{2009-12-10}
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 = [
@@ -47,6 +47,7 @@ Gem::Specification.new do |s|
47
47
  "spec/familytree_v2/json/person/relationship_read.js",
48
48
  "spec/familytree_v2/json/person/relationship_update.js",
49
49
  "spec/familytree_v2/json/search.js",
50
+ "spec/familytree_v2/match_results_spec.rb",
50
51
  "spec/familytree_v2/person_spec.rb",
51
52
  "spec/familytree_v2/search_results_spec.rb",
52
53
  "spec/fs_utils_spec.rb",
@@ -64,6 +65,7 @@ Gem::Specification.new do |s|
64
65
  s.test_files = [
65
66
  "spec/communicator_spec.rb",
66
67
  "spec/familytree_v2/familytree_communicator_spec.rb",
68
+ "spec/familytree_v2/match_results_spec.rb",
67
69
  "spec/familytree_v2/person_spec.rb",
68
70
  "spec/familytree_v2/search_results_spec.rb",
69
71
  "spec/fs_utils_spec.rb",
@@ -80,10 +82,13 @@ Gem::Specification.new do |s|
80
82
 
81
83
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
82
84
  s.add_development_dependency(%q<rspec>, [">= 0"])
85
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
83
86
  else
84
87
  s.add_dependency(%q<rspec>, [">= 0"])
88
+ s.add_dependency(%q<fakeweb>, [">= 0"])
85
89
  end
86
90
  else
87
91
  s.add_dependency(%q<rspec>, [">= 0"])
92
+ s.add_dependency(%q<fakeweb>, [">= 0"])
88
93
  end
89
94
  end
@@ -156,6 +156,47 @@ describe FamilytreeV2::Communicator do
156
156
 
157
157
  end
158
158
 
159
+ describe "match" do
160
+
161
+ before(:each) do
162
+ @fs_com_mock = mock("FsCommunicator")
163
+ @res = mock("HTTP::Response")
164
+ @ft_v2_com = FamilytreeV2::Communicator.new @fs_com_mock
165
+
166
+ @json = read_file('../match_KW3B-NNM.js')
167
+ @res.stub!(:body).and_return(@json)
168
+ @res.stub!(:code).and_return('200')
169
+ @fs_com_mock.stub!(:get).and_return(@res)
170
+ end
171
+
172
+ it "should call the match endpoint" do
173
+ @fs_com_mock.should_receive(:get).with("/familytree/v2/match?name=John")
174
+ @ft_v2_com.match :name => "John"
175
+ end
176
+
177
+ it "should return the MatchResults element" do
178
+ search_results = @ft_v2_com.match :name => "John"
179
+ search_results.class.should == Org::Familysearch::Ws::Familytree::V2::Schema::MatchResults
180
+ search_results.count.should == 4
181
+ end
182
+
183
+ it "should serialize embedded parent parameters" do
184
+ @fs_com_mock.should_receive(:get).with("/familytree/v2/match?father.name=John")
185
+ @ft_v2_com.match :father => {:name => "John"}
186
+ end
187
+
188
+ it "should accept an id as the first parameter" do
189
+ @fs_com_mock.should_receive(:get).with("/familytree/v2/match/KWQS-BBQ")
190
+ @ft_v2_com.match 'KWQS-BBQ'
191
+ end
192
+
193
+ it "should accept an id AND hash if passed" do
194
+ @fs_com_mock.should_receive(:get).with("/familytree/v2/match/KWQS-BBQ?maxResults=5")
195
+ @ft_v2_com.match 'KWQS-BBQ', :maxResults => 5
196
+ end
197
+
198
+ end
199
+
159
200
  describe "reading relationships" do
160
201
 
161
202
  describe "for relationships that already exist" do
@@ -0,0 +1,117 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'ruby-fs-stack/familytree'
3
+
4
+ describe Org::Familysearch::Ws::Familytree::V2::Schema::MatchResults, "parsing match results" do
5
+ FamilyTreeV2 = Org::Familysearch::Ws::Familytree::V2::Schema
6
+
7
+ def read_file(filename)
8
+ fname = File.join(File.dirname(__FILE__),'json',filename)
9
+ File.read(fname)
10
+ end
11
+
12
+ before(:all) do
13
+ json = read_file('match_KW3B-NNM.js')
14
+ familytree = FamilyTreeV2::FamilyTree.from_json JSON.parse(json)
15
+ @match = familytree.matches[0]
16
+ @results = @match.results
17
+ end
18
+
19
+ it "should have a count of 4" do
20
+ @match.count.should == 4
21
+ end
22
+
23
+ it "should parse an xml string and return a MatchResult object" do
24
+ @results.first.should be_instance_of(FamilyTreeV2::MatchResult)
25
+ end
26
+
27
+ it "should have 4 result" do
28
+ @results.should have(4).thing
29
+ end
30
+
31
+ it "should have first result with ref of KW3B-VC8" do
32
+ @results.first.ref.should eql('KW3B-VC8')
33
+ end
34
+
35
+ it "should have first result with a confidence of High" do
36
+ @results.first.confidence.should eql('High')
37
+ end
38
+
39
+ describe "first match person" do
40
+ before(:all) do
41
+ match = @results.first
42
+ @person = match.person
43
+ end
44
+
45
+ it "should keep an alias for ref for v1 migration" do
46
+ @person.ref.should == 'KW3B-VC8'
47
+ end
48
+
49
+ it "should have name of John Flack" do
50
+ @person.name.should eql('John Flack')
51
+ end
52
+
53
+ it "should be male" do
54
+ @person.gender.should eql('Male')
55
+ end
56
+
57
+ it "should have 4 events" do
58
+ @person.events.should have(4).things
59
+ end
60
+
61
+ it "should have birth date of 5 June 1880" do
62
+ @person.birth.date.original.should eql('5 June 1880')
63
+ end
64
+
65
+ it "should have death date of 5 Aug 1953" do
66
+ @person.death.date.original.should eql('5 Aug 1953')
67
+ end
68
+
69
+ end
70
+
71
+ describe "first result person's father" do
72
+ before(:all) do
73
+ match = @results.first
74
+ @person = match.father
75
+ end
76
+
77
+ it "should have name of Alfred Flack" do
78
+ @person.name.should eql('Alfred Flack')
79
+ end
80
+
81
+ it "should be male" do
82
+ @person.gender.should eql('Male')
83
+ end
84
+
85
+ it "should have 0 events" do
86
+ @person.events.should have(0).things
87
+ end
88
+
89
+ it "should have nil birth" do
90
+ @person.birth.should be_nil
91
+ end
92
+ end
93
+
94
+ describe "first result person's mother" do
95
+ before(:all) do
96
+ match = @results.first
97
+ @person = match.mother
98
+ end
99
+
100
+ it "should have name of Sarah Lunt" do
101
+ @person.name.should eql('Sarah Lunt')
102
+ end
103
+
104
+ it "should be female" do
105
+ @person.gender.should eql('Female')
106
+ end
107
+
108
+ it "should have 0 events" do
109
+ @person.events.should have(0).things
110
+ end
111
+ end
112
+
113
+ describe "first result first spouse" do
114
+ # Inherits from SearchResult so this doesn't need to be tested.
115
+ end
116
+ end
117
+
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'ruby-fs-stack'
4
4
  require 'spec'
5
5
  require 'spec/autorun'
6
+ require 'fakeweb'
6
7
 
7
8
  Spec::Runner.configure do |config|
8
9
 
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.1
4
+ version: 0.2.2
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-09 00:00:00 -07:00
12
+ date: 2009-12-10 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: fakeweb
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
25
35
  description: A library that enables you to read and update information with the new.familysearch.org API.
26
36
  email: jimmy.zimmerman@gmail.com
27
37
  executables: []
@@ -62,6 +72,7 @@ files:
62
72
  - spec/familytree_v2/json/person/relationship_read.js
63
73
  - spec/familytree_v2/json/person/relationship_update.js
64
74
  - spec/familytree_v2/json/search.js
75
+ - spec/familytree_v2/match_results_spec.rb
65
76
  - spec/familytree_v2/person_spec.rb
66
77
  - spec/familytree_v2/search_results_spec.rb
67
78
  - spec/fs_utils_spec.rb
@@ -100,6 +111,7 @@ summary: Ruby wrapper for all FamilySearch APIs.
100
111
  test_files:
101
112
  - spec/communicator_spec.rb
102
113
  - spec/familytree_v2/familytree_communicator_spec.rb
114
+ - spec/familytree_v2/match_results_spec.rb
103
115
  - spec/familytree_v2/person_spec.rb
104
116
  - spec/familytree_v2/search_results_spec.rb
105
117
  - spec/fs_utils_spec.rb