familysearch2 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ad5e548141b7a6d73584b857c504c88c3feb072
4
- data.tar.gz: b7cf54907a88b008e5a272842e8fb67cceea837a
3
+ metadata.gz: e5e3a8f176f23c64328144548fd125e888f02a31
4
+ data.tar.gz: e7667eda6b3479a5f3d5b4f24b2bdf1bebcf9f19
5
5
  SHA512:
6
- metadata.gz: fa0414c36da79554166eb3cd0cadb228311a806d8365f75c93bec596a24a70a33aa657931fdaead90384519e0a3e472a03593712331dfbb0bb0650f3394f9c80
7
- data.tar.gz: 34be9a7abff86e6f9cb8791f2724c0424f4a47d1b39fb9c09a2f3154810c5edf8a12320cecfdb5c303a1181a7c8fbb254b4548bbb747e2828be3ddee7f8805e6
6
+ metadata.gz: d24317d59d145938f267d45ff3aee83102a9a61cc163145011a33f82c94512842bff0a5a398d3a7f4dd2c3c50b479788f9932dfeec9b7648d7e78e557aa2a252
7
+ data.tar.gz: da1877d1f1c73d8451fd151112aae458410a99e101e81136469154c640da205457aac292356dc67597d9833fe60b2fe5b09b18fdfde83f97911737e689a1e502
data/Gemfile.lock CHANGED
@@ -4,16 +4,29 @@ PATH
4
4
  familysearch2 (0.1.0)
5
5
  faraday
6
6
  json
7
+ oauth
8
+ rest-client
7
9
 
8
10
  GEM
9
11
  remote: http://rubygems.org/
10
12
  specs:
11
13
  diff-lcs (1.2.5)
14
+ domain_name (0.5.24)
15
+ unf (>= 0.0.5, < 1.0.0)
12
16
  faraday (0.9.1)
13
17
  multipart-post (>= 1.2, < 3)
18
+ http-cookie (1.0.2)
19
+ domain_name (~> 0.5)
14
20
  json (1.8.3)
21
+ mime-types (2.6.1)
15
22
  multipart-post (2.0.0)
23
+ netrc (0.10.3)
24
+ oauth (0.4.7)
16
25
  rake (10.4.2)
26
+ rest-client (2.0.0.rc1)
27
+ http-cookie (>= 1.0.2, < 2.0)
28
+ mime-types (>= 1.16, < 3.0)
29
+ netrc (~> 0.8)
17
30
  rspec (3.3.0)
18
31
  rspec-core (~> 3.3.0)
19
32
  rspec-expectations (~> 3.3.0)
@@ -27,6 +40,7 @@ GEM
27
40
  diff-lcs (>= 1.2.0, < 2.0)
28
41
  rspec-support (~> 3.3.0)
29
42
  rspec-support (3.3.0)
43
+ unf (0.2.0.beta2)
30
44
 
31
45
  PLATFORMS
32
46
  ruby
data/api_library ADDED
@@ -0,0 +1,21 @@
1
+ discussions => https://sandbox.familysearch.org/platform/discussions/discussions
2
+ user-collections => https://sandbox.familysearch.org/platform/sources/collections
3
+ current-user => https://sandbox.familysearch.org/platform/users/current
4
+ child-and-parents-relationships => https://sandbox.familysearch.org/platform/tree/child-and-parents-relationships
5
+ authorities => https://integration.familysearch.org/authorities
6
+ reservation => https://integration.familysearch.org/reservation
7
+ memories => https://sandbox.familysearch.org/platform/memories/memories
8
+ fs-identity-v2-login => https://integration.familysearch.org/identity/v2/login
9
+ http://oauth.net/core/2.0/endpoint/token => https://integration.familysearch.org/cis-web/oauth2/v3/token
10
+ http://oauth.net/core/2.0/endpoint/authorize => https://integration.familysearch.org/cis-web/oauth2/v3/authorization
11
+ redirect => https://sandbox.familysearch.org/platform/redirect
12
+ relationships => https://sandbox.familysearch.org/platform/tree/relationships
13
+ registration => https://integration.familysearch.org/cis-web/pages/registration/registration.html
14
+ pending-modifications => https://sandbox.familysearch.org/platform/pending-modifications
15
+ persons => https://sandbox.familysearch.org/platform/tree/persons
16
+ fs-identity-v2-permission => https://integration.familysearch.org/identity/v2/permission
17
+ fs-identity-v2-logout => https://integration.familysearch.org/identity/v2/logout
18
+ couple-relationships => https://sandbox.familysearch.org/platform/tree/couple-relationships
19
+ source-descriptions => https://sandbox.familysearch.org/platform/sources/descriptions
20
+ current-user-person => https://sandbox.familysearch.org/platform/tree/current-person
21
+ fs-identity-v2-session => https://integration.familysearch.org/identity/v2/session
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency 'json'
24
24
  spec.add_dependency 'faraday'
25
+ spec.add_dependency 'rest-client'
26
+ spec.add_dependency 'oauth'
25
27
 
26
28
  spec.add_development_dependency 'rspec'
27
29
  spec.add_development_dependency "bundler", "~> 1.10"
@@ -1,3 +1,3 @@
1
1
  module Familysearch2git
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/familysearch2.rb CHANGED
@@ -1,19 +1,26 @@
1
1
  require 'json'
2
2
  require 'faraday'
3
+ require 'time'
4
+ require 'cgi'
3
5
 
4
6
  module Familyseach2
7
+
5
8
  class Client
6
9
 
7
10
  def initialize(params = {})
8
- @access_token = params[:access_token] # if options[:access_token]
9
11
  @logger = params[:logger]
10
12
  @key = params[:key]
11
13
  @base_url = get_base_url(params[:environment])
12
14
  @agent = Faraday.new(@base_url) do |faraday|
13
15
  faraday.headers['Accept'] = 'application/x-fs-v1+json,application/x-gedcomx-atom+json,application/json'
14
- faraday.authorization('Bearer',@access_token) if @access_token
15
16
  faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
16
17
  end
18
+ get_access_token(params[:username],params[:password],params[:environment])
19
+ @agent
20
+ end
21
+
22
+ def get_agent
23
+ @agent
17
24
  end
18
25
 
19
26
  def get_base_url(env)
@@ -24,32 +31,72 @@ module Familyseach2
24
31
  base_url
25
32
  end
26
33
 
27
- def basic_auth(username,password,key=nil)
28
- self.search
29
- @key ||= key if key
30
- @agent.basic_auth username, password
31
- @parsed_discovery = JSON.parse(@discovery)
32
- response = @agent.get @parsed_discovery['links']['fs-identity-v2-login']['href'], :dataFormat => 'application/json', :key => @key
33
- puts response.inspect
34
- @access_token = JSON.parse(response.body)['authentication']
34
+ def get_access_token(username,password,env)
35
+ meta
36
+ url = JSON.parse(@discovery)['links']['fs-identity-v2-login']['href']
37
+ @client_id = "a02j0000007rtRiAAI"
38
+ RestClient::Resource.new url, username, password
39
+
40
+ request_url = get_base_url(env) + "/identity/v2/request_token"
41
+
42
+ time = Time.now.utc.to_i.to_s
43
+
44
+ request_response = ""
45
+ begin
46
+ request_response = RestClient. get "#{request_url}?oauth_consumer_key=#{@client_id}&oauth_signature_method=PLAINTEXT&oauth_signature=%26&oauth_timestamp=#{time}&oauth_nonce=123456789"
47
+ rescue => e
48
+ puts e
49
+ end
50
+
51
+ access_token = JSON.parse(CGI::parse(request_response).to_json)['oauth_token']
52
+ @access_token = access_token.to_s.sub!('["', '')[0...-2]
35
53
  @agent.authorization('Bearer',@access_token)
36
- return true
37
54
  end
38
55
 
39
- def search
40
- @discovery ||= get_search
56
+ # gets the url in api-library
57
+ def get_url(call)
58
+ lines = []
59
+ url = ""
60
+ File.open("api_library", "r").each_line do |line|
61
+ lines << line
62
+ end
63
+
64
+ lines.each do |x|
65
+ line = x.split("=>")
66
+ url = line[1].strip if line[0].strip == call
67
+ end
68
+ url
41
69
  end
42
70
 
43
- def connection
44
- @connection = Faraday.new(url: @base_url) do |faraday|
45
- faraday.request :url_encoded # form-encode POST params
46
- faraday.response :logger # log requests to STDOUT
47
- faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
71
+ def update_library
72
+ link_names = []
73
+ name_hrefs = []
74
+
75
+ # get links
76
+ parsed_links = JSON.parse(@discovery)['links']
77
+ parsed_links.each do |x|
78
+ link_names << x.to_s.split(' ')[0].sub!('["', '')[0...-2]
79
+ end
80
+
81
+ # get hrefs
82
+ link_names.each do |x|
83
+ temp = JSON.parse(@discovery)['links'][x]['href']
84
+ if temp.to_s != ""
85
+ name_hrefs << ("#{x} => #{temp}")
86
+ end
48
87
  end
88
+
89
+ File.open('api_library', "w+") do |f|
90
+ name_hrefs.each { |element| f.puts(element) }
91
+ end
92
+ end
93
+
94
+ def meta
95
+ @discovery ||= get_meta
49
96
  end
50
97
 
51
98
  private
52
- def get_search
99
+ def get_meta
53
100
  result = @agent.get('/.well-known/app-meta')
54
101
  result.body
55
102
  end
data/test.rb CHANGED
@@ -1,5 +1,17 @@
1
+ require 'rest-client'
2
+ require 'oauth'
3
+
1
4
  require File.expand_path(File.dirname(__FILE__) + '/lib/familysearch2')
2
5
 
3
- client = Familyseach2::Client.new(environment: "production")
4
- client.basic_auth('','')
6
+ @client = Familyseach2::Client.new(username: "", password: "", environment: "sandbox")
7
+ @client.update_library
8
+
9
+ agent = @client.get_agent
10
+
11
+ response = agent.get '/platform/users/current'
12
+ puts response.body
13
+ # RestClient.get "https://sandbox.familysearch.org/platform/users/current", {:Authorization => "Bearer #{@access_token}"}
14
+
15
+
16
+
5
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: familysearch2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kinezu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-11 00:00:00.000000000 Z
11
+ date: 2015-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: oauth
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rspec
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -97,6 +125,7 @@ files:
97
125
  - LICENSE.txt
98
126
  - README.md
99
127
  - Rakefile
128
+ - api_library
100
129
  - bin/console
101
130
  - bin/setup
102
131
  - familysearch2.gemspec