linkedin-saddle-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +9 -0
- data/LICENSE +19 -0
- data/README.md +13 -0
- data/lib/linkedin-client.rb +57 -0
- data/lib/linkedin-client/endpoints/v1.rb +26 -0
- data/lib/linkedin-client/exceptions.rb +18 -0
- data/lib/linkedin-client/stub.rb +28 -0
- data/lib/linkedin-client/version.rb +5 -0
- data/linkedin-client.gemspec +26 -0
- data/spec/_creds.stub.rb +3 -0
- data/spec/integration/v1_spec.rb +39 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/stub/stub_spec.rb +23 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a1b9ff5918bbb5a2541647584c70e78f20838ac9
|
4
|
+
data.tar.gz: f6761aac0888ceee401f978b524ecf44c55d6346
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ceb21c6b7d9ed0ae4c06e80c3d3193fe1370790af8e555c049d5e479d3f9ba7b415de28b01a5e176a8f40e58a18963771dfb3637af2d54382df0ab7242e8dff8
|
7
|
+
data.tar.gz: ba5279931619b62d4128170cbd9f408309df60744106c1b09e514ea9baedaba52e54fba029abb2028e4743d310d4837f4296fc9d56dfa6a3f0c1e3e04984e47a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014, Roman Fuchs
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Ruby LinkedIn OAuth 2 client
|
2
|
+
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
|
6
|
+
client = LinkedIn::Client.create(
|
7
|
+
:access_token => YOUR_OAUTH2_ACCESS_TOKEN
|
8
|
+
)
|
9
|
+
profile = client.account.get_profile
|
10
|
+
|
11
|
+
|
12
|
+
## License
|
13
|
+
linkedin-client is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'saddle'
|
4
|
+
require 'saddle/middleware/authentication/oauth2'
|
5
|
+
|
6
|
+
require 'linkedin-client/stub'
|
7
|
+
require 'linkedin-client/version'
|
8
|
+
|
9
|
+
|
10
|
+
module LinkedIn
|
11
|
+
|
12
|
+
class Client < Saddle::Client
|
13
|
+
extend LinkedIn::Stub
|
14
|
+
|
15
|
+
def initialize args
|
16
|
+
args.each do |k,v|
|
17
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.host
|
22
|
+
@host || 'api.linkedin.com'
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.path_prefix
|
26
|
+
@path_prefix || ''
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.use_ssl
|
30
|
+
@use_ssl || true
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.num_retries
|
34
|
+
@num_retries || 1
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.timeout
|
38
|
+
# seconds
|
39
|
+
@timeout || 5
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.request_style
|
43
|
+
@request_style || :json
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.option_fields
|
47
|
+
@option_fields = ['id', 'email-address', 'first-name', 'last-name', 'num-connections', 'positions', 'three-current-positions', 'three-past-positions', 'educations']
|
48
|
+
end
|
49
|
+
|
50
|
+
add_middleware({
|
51
|
+
:klass => Saddle::Middleware::Authentication::OAuth2,
|
52
|
+
:args => ['oauth2_access_token'],
|
53
|
+
})
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'saddle/endpoint'
|
4
|
+
|
5
|
+
module LinkedIn
|
6
|
+
module Endpoints
|
7
|
+
|
8
|
+
class V1 < Saddle::TraversalEndpoint
|
9
|
+
|
10
|
+
def get_profile(id, opts = {})
|
11
|
+
get_with_format("people/id=#{id}", {}, opts)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_info_by_fields(fields = LinkedIn::Client.option_fields, opts = {})
|
15
|
+
get_with_format("people/~:(#{fields.join(',')})", {}, opts)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def get_with_format(url, params={}, options={})
|
21
|
+
get(url, params.merge({:format => LinkedIn::Client.request_style}), options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
##
|
4
|
+
# Exceptions for using the LinkedIn client
|
5
|
+
# It is recommended that you handle these.
|
6
|
+
##
|
7
|
+
|
8
|
+
module LinkedIn
|
9
|
+
|
10
|
+
class GenericException < StandardError; end
|
11
|
+
|
12
|
+
class TimeoutError < GenericException; end
|
13
|
+
|
14
|
+
# Some problems might take care of themselves if you try again later. Others won't.
|
15
|
+
class TemporaryError < GenericException; end # fire warnings on these
|
16
|
+
class PermanentError < GenericException; end # fire errors on these
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'linkedin-client/endpoints/v1'
|
4
|
+
|
5
|
+
# This allows us to stub out live calls when testing from calling projects
|
6
|
+
|
7
|
+
module LinkedIn
|
8
|
+
module Stub
|
9
|
+
|
10
|
+
# Setup stubbing for all endpoints
|
11
|
+
def stub!
|
12
|
+
LinkedIn::Endpoints::V1.any_instance.stub(:get_profile).and_return( Stub::Data::PROFILE )
|
13
|
+
end
|
14
|
+
|
15
|
+
# Test data for stubs to return
|
16
|
+
module Data
|
17
|
+
|
18
|
+
PROFILE = {
|
19
|
+
"firstName"=>"Henry",
|
20
|
+
"headline"=>"Software Engineer, Growth at Airbnb",
|
21
|
+
"lastName"=>"Cai 蔡明航",
|
22
|
+
"siteStandardProfileRequest"=> {
|
23
|
+
"url"=> "https://www.linkedin.com/profile/view?id=17907854&authType=name&authToken=Y7oQ&trk=api*a4138181*s4202511*"}
|
24
|
+
}.freeze
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/linkedin-client/version', __FILE__)
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'linkedin-saddle-client'
|
9
|
+
s.version = ::LinkedIn::VERSION
|
10
|
+
s.authors = ['Henry Cai']
|
11
|
+
s.email = ['minghangcai@gmail.com']
|
12
|
+
s.description = %q{LinkedIn OAuth2 client}
|
13
|
+
s.summary = %q{
|
14
|
+
This is a LinkedIn OAuth2 client implemented on Saddle
|
15
|
+
}
|
16
|
+
s.homepage = 'https://github.com/hcai/linkedin-client.git'
|
17
|
+
s.license = 'MIT'
|
18
|
+
|
19
|
+
s.require_path = 'lib'
|
20
|
+
s.files = `git ls-files`.split($\)
|
21
|
+
s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
22
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
23
|
+
|
24
|
+
s.add_dependency 'saddle', '~> 0.0.46'
|
25
|
+
s.add_dependency 'simple_oauth', '~> 0.2.0'
|
26
|
+
end
|
data/spec/_creds.stub.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
|
7
|
+
###
|
8
|
+
# NOTE: This spec will actually hit LinkedIn's servers
|
9
|
+
###
|
10
|
+
|
11
|
+
describe 'LinkedIn::Endpoints::People' do
|
12
|
+
context "Test integration of people endpoint" do
|
13
|
+
|
14
|
+
# Skip if the creds aren't setup
|
15
|
+
if defined?(TEST_ACCESS_TOKEN)
|
16
|
+
|
17
|
+
before :each do
|
18
|
+
@client = LinkedIn::Client.create(:oauth2_access_token => TEST_ACCESS_TOKEN)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'get my profile' do
|
22
|
+
response = @client.v1.get_profile('ARz7eS698N')
|
23
|
+
response.should be_a(Hash)
|
24
|
+
response['firstName'].should_not be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'gets default fields' do
|
28
|
+
response = @client.v1.get_info_by_fields()
|
29
|
+
response.should be_a(Hash)
|
30
|
+
pp response
|
31
|
+
response['threeCurrentPositions'].should_not be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
else
|
35
|
+
puts "You should put valid creds in _creds.rb"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'linkedin-client'
|
4
|
+
|
5
|
+
# Load credentials from ENV if possible, or load from _creds.rb
|
6
|
+
if ENV['TEST_USER_TOKEN'] && ENV['TEST_USER_ID'] && ENV['TEST_USER_URL']
|
7
|
+
TEST_USER_TOKEN = ENV['TEST_USER_TOKEN']
|
8
|
+
else
|
9
|
+
begin
|
10
|
+
require '_creds'
|
11
|
+
rescue LoadError
|
12
|
+
puts "Using _creds.stub.rb, create a _creds.rb with actual credentials for a live test."
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe LinkedIn::Stub do
|
6
|
+
context "can stub out calls" do
|
7
|
+
|
8
|
+
let (:client) { LinkedIn::Client.create }
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
LinkedIn::Client.stub!
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "and return test data" do
|
15
|
+
|
16
|
+
it "for client.people.profile_basic" do
|
17
|
+
client.poeple.get_profile.should == LinkedIn::Stub::Data::PROFILE
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: linkedin-saddle-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Henry Cai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: saddle
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.46
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.46
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: simple_oauth
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
41
|
+
description: LinkedIn OAuth2 client
|
42
|
+
email:
|
43
|
+
- minghangcai@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- lib/linkedin-client.rb
|
53
|
+
- lib/linkedin-client/endpoints/v1.rb
|
54
|
+
- lib/linkedin-client/exceptions.rb
|
55
|
+
- lib/linkedin-client/stub.rb
|
56
|
+
- lib/linkedin-client/version.rb
|
57
|
+
- linkedin-client.gemspec
|
58
|
+
- spec/_creds.stub.rb
|
59
|
+
- spec/integration/v1_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
- spec/stub/stub_spec.rb
|
62
|
+
homepage: https://github.com/hcai/linkedin-client.git
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.2.2
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: This is a LinkedIn OAuth2 client implemented on Saddle
|
86
|
+
test_files:
|
87
|
+
- spec/_creds.stub.rb
|
88
|
+
- spec/integration/v1_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- spec/stub/stub_spec.rb
|