familysearch 0.3.0 → 0.4.0

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/README.md CHANGED
@@ -8,7 +8,7 @@ You can install it from the commandline.
8
8
 
9
9
  Or add it to a Gemfile for use with Bundler
10
10
 
11
- gem "familysearch", "~> 0.3.0 "
11
+ gem "familysearch", "~> 0.4.0 "
12
12
 
13
13
 
14
14
  ## Basic Usage
@@ -29,8 +29,17 @@ Here's how to use it
29
29
  response = client.get(client.discovery['links']['current-user-person']['href'])
30
30
  response.status #=> 200
31
31
 
32
- # The response contains a Hash object on the body attribute.
32
+ # The response body contains a FamilySearch::Gedcomx::FamilySearch object.
33
+ # This is technically a Hash, so you could do the following
33
34
  response.body['persons'][0]['display']['name']
35
+
36
+ # The FamilySearch::Gedcomx::FamilySearch object also provides convenience methods
37
+ # and the hash elements have method accessors
38
+ person = response.body.persons[0]
39
+ person.full_name #=> "Marshall P Felch"
40
+ person.surname #=> "Felch"
41
+ person.birth # => a FamilySearch::Gedcomx::Fact object
42
+
34
43
 
35
44
  ## Discovery Resource
36
45
 
@@ -60,6 +69,12 @@ The above code is equivalent to the following:
60
69
 
61
70
  response = client.get 'https://sandbox.familysearch.org/platform/tree/persons/KWQX-52J'
62
71
 
72
+ ## FamilySearch::Gedcomx
73
+
74
+ A separate `familysearch-gedcomx` gem is pulled in as a dependency for the `familysearch` gem. This provides a Ruby object structure that matches the [application/x-fs-v1+json](https://familysearch.org/developers/docs/api/fs_json) hypermedia type. It also provides convenience methods and graph (pedigree) traversal functionality.
75
+
76
+ For more information visit the [familysearch-gedcomx](https://github.com/jimmyz/familysearch-gedcomx-rb) homepage.
77
+
63
78
  ## Faraday
64
79
 
65
80
  This gem depends upon the wonderful `faraday` gem for handling HTTP calls. One of the advantages of this is that you could possibly swap out underlying http libraries. Currently, it utilizes the Net::HTTP library, but in the future it could potentially support other libraries such as EventMachine's asynchronous http library.
@@ -73,12 +88,14 @@ This gem makes use of the awesome `multi_json` gem. This allows you to utilize f
73
88
  Next on the roadmap:
74
89
 
75
90
  * Support post, put, delete, head, etc. from the FamilySearch::URLTemplate objec. (currently only supports get)
76
- * Better object deserialization. Currently, everything is just a dumb Hash. I'd like to be able to allow an option to pass in another middleware for smarter objects (pershaps Hashie::Mash or Rash, or some sort of GedcomX model).
91
+ * Better Faraday configuration options for the client.
92
+ * Testing of more endpoints (search, match, etc.)
93
+ * JSON serialization for put, post, etc.
77
94
  * More documentation examples.
78
95
 
79
96
  ## Bugs and Feature Requests
80
97
 
81
- Please file bug reports and
98
+ Please file bug reports and enhancement requests on [the issue tracker](https://github.com/jimmyz/familysearch-rb/issues).
82
99
 
83
100
  ## Copyright
84
101
 
data/familysearch.gemspec CHANGED
@@ -20,6 +20,8 @@ Gem::Specification.new do |s|
20
20
  s.add_dependency("faraday", ["~> 0.8.4"])
21
21
  s.add_dependency("faraday_middleware", ["~> 0.9.0"])
22
22
  s.add_dependency("multi_json", ["~> 1.5.0"])
23
+ s.add_dependency("addressable", ["~> 2.3.3"])
24
+ s.add_dependency("familysearch-gedcomx", ["~> 1.0.0"])
23
25
  s.add_development_dependency("rspec", ["~> 2.13.0"])
24
26
  s.add_development_dependency("shoulda", ["~> 3.3.2"])
25
27
  s.add_development_dependency("bundler", [">= 1.2.3"])
@@ -79,6 +79,7 @@ module FamilySearch
79
79
  @agent = Faraday.new(@base_url) do |faraday|
80
80
  faraday.response :familysearch_errors
81
81
  faraday.response :logger, options[:logger] if options[:logger]
82
+ faraday.response :gedcomx_parser
82
83
  faraday.response :multi_json
83
84
  faraday.response :follow_redirects, :limit => 3, :standards_compliant => true
84
85
  faraday.headers['Accept'] = 'application/x-fs-v1+json'
@@ -0,0 +1,15 @@
1
+ require 'familysearch/gedcomx'
2
+
3
+ module FamilySearch
4
+ module Middleware
5
+ # Parse
6
+ class GedcomxParser < Faraday::Response::Middleware
7
+ # The method that has MultiJson parse the json string.
8
+ def parse(body)
9
+ FamilySearch::Gedcomx::FamilySearch.new body
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ Faraday.register_middleware :response, :gedcomx_parser => FamilySearch::Middleware::GedcomxParser
@@ -1,2 +1,3 @@
1
1
  require 'familysearch/middleware/response/familysearch_errors'
2
- require 'familysearch/middleware/response/multi_json'
2
+ require 'familysearch/middleware/response/multi_json'
3
+ require 'familysearch/middleware/response/familysearch_gedcomx'
@@ -1,3 +1,4 @@
1
+ require 'addressable/template'
1
2
  module FamilySearch
2
3
  # Used to make calls on templates that are exposed through the Discovery Resource.
3
4
  #
@@ -82,9 +83,9 @@ module FamilySearch
82
83
  def get(template_values)
83
84
  raise FamilySearch::Error::MethodNotAllowed unless allow.include?('get')
84
85
  template_values = validate_values(template_values)
85
- url = make_url(template_values)
86
- params = make_params(template_values)
87
- @client.get url, params
86
+ t = Addressable::Template.new(@template)
87
+ url = t.expand(template_values).to_s
88
+ @client.get url
88
89
  end
89
90
 
90
91
  private
@@ -107,26 +108,5 @@ module FamilySearch
107
108
  end
108
109
  stringified_hash
109
110
  end
110
-
111
- def make_url(template_values)
112
- url = @template.gsub(/\{\?[^}]*\}/,'')
113
- template_values.each do |k,v|
114
- to_replace = "{#{k}}"
115
- url.gsub!(to_replace,v)
116
- end
117
- url
118
- end
119
-
120
- def make_params(template_values)
121
- to_remove = url_values
122
- to_remove.each do |v|
123
- template_values.delete(v)
124
- end
125
- template_values
126
- end
127
-
128
- def url_values
129
- @template.scan(/\{(\w*)\}/).flatten
130
- end
131
111
  end
132
112
  end
@@ -1,4 +1,4 @@
1
1
  module FamilySearch
2
2
  # The version of the familysearch gem. Can be accessed from code FamilySearch::VERSION
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
data/lib/familysearch.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'familysearch/version'
2
- require 'familysearch/client'
2
+ require 'familysearch/gedcomx' # located in dependent familysearch-gedcomx gem
3
+ require 'familysearch/client'
data/spec/client_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'familysearch/client'
2
+ require 'familysearch'
3
3
 
4
4
  describe FamilySearch::Client do
5
5
 
@@ -226,7 +226,7 @@ describe FamilySearch::Client do
226
226
  it "should allow you to make a call to a template and get a result" do
227
227
  VCR.use_cassette('person_by_id') do
228
228
  result = client.template('person').get 'pid' => 'KWQX-52J'
229
- result.body.should be_kind_of(Hash)
229
+ result.body.should be_instance_of(FamilySearch::Gedcomx::FamilySearch)
230
230
  end
231
231
  end
232
232
  end
@@ -91,25 +91,25 @@ describe FamilySearch::URLTemplate do
91
91
 
92
92
  it "should call get on the client with the url and values on the querystring" do
93
93
  VCR.use_cassette('person_with_relationship') do
94
- client.should_receive(:get).with('https://sandbox.familysearch.org/platform/tree/persons-with-relationships',{'person' => 'KWQX-52J'}).and_call_original
94
+ client.should_receive(:get).with('https://sandbox.familysearch.org/platform/tree/persons-with-relationships?person=KWQX-52J').and_call_original
95
95
  template.get 'person' => 'KWQX-52J'
96
96
  end
97
97
  end
98
98
 
99
99
  it "should call get on the client with the url and no querystring if nothing needs to be called" do
100
100
  VCR.use_cassette('person_by_id') do
101
- client.should_receive(:get).with('https://sandbox.familysearch.org/platform/tree/persons/KWQX-52J',{})
101
+ client.should_receive(:get).with('https://sandbox.familysearch.org/platform/tree/persons/KWQX-52J')
102
102
  person_template.get 'pid' => 'KWQX-52J'
103
103
  end
104
104
  end
105
105
 
106
106
  it "should accept symbols in the values hash" do
107
107
  VCR.use_cassette('person_with_relationship') do
108
- client.should_receive(:get).with('https://sandbox.familysearch.org/platform/tree/persons-with-relationships',{'person' => 'KWQX-52J'}).and_call_original
108
+ client.should_receive(:get).with('https://sandbox.familysearch.org/platform/tree/persons-with-relationships?person=KWQX-52J').and_call_original
109
109
  template.get :person => 'KWQX-52J'
110
110
  end
111
111
  VCR.use_cassette('person_by_id') do
112
- client.should_receive(:get).with('https://sandbox.familysearch.org/platform/tree/persons/KWQX-52J',{})
112
+ client.should_receive(:get).with('https://sandbox.familysearch.org/platform/tree/persons/KWQX-52J')
113
113
  person_template.get :pid => 'KWQX-52J'
114
114
  end
115
115
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: familysearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
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-03-28 00:00:00.000000000 Z
12
+ date: 2013-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -59,6 +59,38 @@ dependencies:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.5.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: addressable
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.3.3
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.3.3
78
+ - !ruby/object:Gem::Dependency
79
+ name: familysearch-gedcomx
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.0.0
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.0.0
62
94
  - !ruby/object:Gem::Dependency
63
95
  name: rspec
64
96
  requirement: !ruby/object:Gem::Requirement
@@ -160,6 +192,7 @@ files:
160
192
  - lib/familysearch/error.rb
161
193
  - lib/familysearch/middleware.rb
162
194
  - lib/familysearch/middleware/response/familysearch_errors.rb
195
+ - lib/familysearch/middleware/response/familysearch_gedcomx.rb
163
196
  - lib/familysearch/middleware/response/multi_json.rb
164
197
  - lib/familysearch/url_template.rb
165
198
  - lib/familysearch/version.rb