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 +2 -1
- data/README.md +6 -4
- data/geni.gemspec +3 -3
- data/lib/{array.rb → array_hacks.rb} +0 -0
- data/lib/geni.rb +4 -5
- data/lib/geni/base.rb +3 -1
- data/lib/geni/client.rb +43 -11
- data/lib/geni/family.rb +1 -6
- data/lib/geni/profile.rb +2 -2
- data/lib/{oauth.rb → oauth_hacks.rb} +0 -0
- metadata +5 -5
    
        data/.gitignore
    CHANGED
    
    
    
        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 | 
| 15 | 
            -
                  :app_secret | 
| 16 | 
            -
                  : | 
| 14 | 
            +
                  :app_id     => 'XX',
         | 
| 15 | 
            +
                  :app_secret => 'XX',
         | 
| 16 | 
            +
                  :token      => 'XX'
         | 
| 17 17 | 
             
                })
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                me = geni.get_profile
         | 
| 18 20 |  | 
| 19 | 
            -
                profile = geni. | 
| 21 | 
            +
                profile = geni.get_profile('an_id')
         | 
| 20 22 |  | 
| 21 23 | 
             
                puts profile.name
         | 
| 22 24 | 
             
                puts profile.birth_date
         | 
    
        data/geni.gemspec
    CHANGED
    
    | @@ -2,7 +2,7 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            Gem::Specification.new do |s|
         | 
| 4 4 | 
             
              s.name = %q{geni}
         | 
| 5 | 
            -
              s.version = "0.0. | 
| 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/ | 
| 23 | 
            -
                 "lib/ | 
| 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
         | 
    
        data/lib/geni.rb
    CHANGED
    
    
    
        data/lib/geni/base.rb
    CHANGED
    
    
    
        data/lib/geni/client.rb
    CHANGED
    
    | @@ -1,22 +1,54 @@ | |
| 1 1 | 
             
            module Geni
         | 
| 2 2 | 
             
              class Client
         | 
| 3 3 |  | 
| 4 | 
            -
                SITE | 
| 4 | 
            +
                SITE              = 'https://www.geni.com'
         | 
| 5 | 
            +
                ACCESS_TOKEN_PATH = '/oauth/token'
         | 
| 5 6 |  | 
| 6 | 
            -
                attr_reader : | 
| 7 | 
            +
                attr_reader :oauth_client, :access_token
         | 
| 7 8 |  | 
| 8 9 | 
             
                def initialize(params = {})
         | 
| 9 | 
            -
                  @ | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 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  | 
| 15 | 
            -
                   | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
                     | 
| 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
         | 
    
        data/lib/geni/family.rb
    CHANGED
    
    | @@ -33,12 +33,7 @@ module Geni | |
| 33 33 | 
             
                end
         | 
| 34 34 |  | 
| 35 35 | 
             
                def profiles(nodes)
         | 
| 36 | 
            -
                  nodes.collect  | 
| 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
         | 
    
        data/lib/geni/profile.rb
    CHANGED
    
    | @@ -55,8 +55,8 @@ module Geni | |
| 55 55 |  | 
| 56 56 | 
             
                def immediate_family
         | 
| 57 57 | 
             
                  @immediate_family ||= Geni::Family.new({
         | 
| 58 | 
            -
                    : | 
| 59 | 
            -
                    :attrs | 
| 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:  | 
| 4 | 
            +
              hash: 25
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 0
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.0. | 
| 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/ | 
| 66 | 
            -
            - lib/ | 
| 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
         |