geni 0.0.2 → 0.0.3

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/.gitignore CHANGED
@@ -3,4 +3,5 @@ Thumbs.db
3
3
  .DS_Store
4
4
  *.gem
5
5
  .rvmrc
6
- ~*
6
+ ~*
7
+ test.rb
data/README.md CHANGED
@@ -11,12 +11,14 @@ This library needs some specs !
11
11
  # Example usage
12
12
 
13
13
  geni = Geni::Client.new({
14
- :app_id => 'XX',
15
- :app_secret => 'XX',
16
- :access_token => an_oauth_access_token
14
+ :app_id => 'XX',
15
+ :app_secret => 'XX',
16
+ :token => 'XX'
17
17
  })
18
+
19
+ me = geni.get_profile
18
20
 
19
- profile = geni.profile('an_id')
21
+ profile = geni.get_profile('an_id')
20
22
 
21
23
  puts profile.name
22
24
  puts profile.birth_date
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{geni}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Aurélien Malisart"]
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
19
19
  ".gitignore",
20
20
  "README.md",
21
21
  "lib/geni.rb",
22
- "lib/array.rb",
23
- "lib/oauth.rb",
22
+ "lib/array_hacks.rb",
23
+ "lib/oauth_hacks.rb",
24
24
  "lib/geni/base.rb",
25
25
  "lib/geni/client.rb",
26
26
  "lib/geni/family.rb",
File without changes
@@ -1,8 +1,7 @@
1
- require 'oauth'
2
- require 'array'
1
+ require 'oauth2'
2
+ require 'oauth_hacks'
3
+ require 'array_hacks'
3
4
  require 'geni/client'
4
5
  require 'geni/base'
5
6
  require 'geni/profile'
6
- require 'geni/family'
7
-
8
- puts "OK"
7
+ require 'geni/family'
@@ -1,7 +1,9 @@
1
1
  module Geni
2
2
  class Base
3
+ attr_reader :client
4
+
3
5
  def initialize(params = {})
4
- @access_token = params[:access_token]
6
+ @client = params[:client]
5
7
  params[:attrs].each_pair do |attr, value|
6
8
  instance_variable_set("@#{attr}".to_sym, value)
7
9
  end
@@ -1,22 +1,54 @@
1
1
  module Geni
2
2
  class Client
3
3
 
4
- SITE = 'https://www.geni.com'
4
+ SITE = 'https://www.geni.com'
5
+ ACCESS_TOKEN_PATH = '/oauth/token'
5
6
 
6
- attr_reader :app_id, :app_secret, :access_token
7
+ attr_reader :oauth_client, :access_token
7
8
 
8
9
  def initialize(params = {})
9
- @app_id = params[:app_id]
10
- @app_secret = params[:app_secret]
11
- @access_token = params[:access_token]
10
+ @oauth_client = OAuth2::Client.new(params[:app_id], params[:app_secret],
11
+ :site => SITE,
12
+ :parse_json => true,
13
+ :access_token_path => ACCESS_TOKEN_PATH
14
+ )
15
+
16
+ @access_token = OAuth2::AccessToken.new(oauth_client, params[:token])
12
17
  end
13
18
 
14
- def profile(id = nil)
15
- profile_id = id.nil? ? '' : "-#{id}"
16
- Geni::Profile.new({
17
- :access_token => @access_token,
18
- :attrs => @access_token.get("/api/profile#{profile_id}")
19
- })
19
+ def get_profile(id_or_ids = nil)
20
+ if id_or_ids.nil?
21
+ url = "/api/profile"
22
+ elsif id_or_ids.kind_of?(Array)
23
+ if id_or_ids.any?
24
+ url = "/api/profile-#{id_or_ids.join(',')}"
25
+ else
26
+ return []
27
+ end
28
+ else
29
+ url = "/api/profile-#{id_or_ids}"
30
+ end
31
+
32
+ results = access_token.get(url)
33
+ results = results['results'] if results.has_key?('results')
34
+
35
+ profiles = [results].flatten.collect do |profile_attrs|
36
+ Geni::Profile.new({
37
+ :client => self,
38
+ :attrs => profile_attrs
39
+ })
40
+ end
41
+
42
+ id_or_ids.kind_of?(Array) ? profiles : profiles.first
43
+ end
44
+
45
+ class << self
46
+ def redirect_uri(request)
47
+ uri = URI.parse(request.url)
48
+ uri.path = '/callback'
49
+ uri.query = nil
50
+ uri.to_s
51
+ end
20
52
  end
21
53
  end
22
54
  end
@@ -33,12 +33,7 @@ module Geni
33
33
  end
34
34
 
35
35
  def profiles(nodes)
36
- nodes.collect do |node|
37
- Geni::Profile.new({
38
- :access_token => @access_token,
39
- :attrs => @access_token.get("/api/#{node['id']}")
40
- })
41
- end
36
+ client.get_profile(nodes.collect { |node| node['id'].split('-').last })
42
37
  end
43
38
  end
44
39
  end
@@ -55,8 +55,8 @@ module Geni
55
55
 
56
56
  def immediate_family
57
57
  @immediate_family ||= Geni::Family.new({
58
- :access_token => @access_token,
59
- :attrs => @access_token.get("/api/profile-#{id}/immediate-family")
58
+ :client => client,
59
+ :attrs => client.access_token.get("/api/profile-#{id}/immediate-family")
60
60
  })
61
61
  end
62
62
  end
File without changes
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geni
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Aur\xC3\xA9lien Malisart"
@@ -62,8 +62,8 @@ files:
62
62
  - .gitignore
63
63
  - README.md
64
64
  - lib/geni.rb
65
- - lib/array.rb
66
- - lib/oauth.rb
65
+ - lib/array_hacks.rb
66
+ - lib/oauth_hacks.rb
67
67
  - lib/geni/base.rb
68
68
  - lib/geni/client.rb
69
69
  - lib/geni/family.rb