linkedin2 0.0.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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +84 -0
- data/Rakefile +6 -0
- data/lib/linkedin/api/authentication.rb +23 -0
- data/lib/linkedin/client.rb +34 -0
- data/lib/linkedin/configuration.rb +64 -0
- data/lib/linkedin/error.rb +9 -0
- data/lib/linkedin/utils.rb +8 -0
- data/lib/linkedin/version.rb +3 -0
- data/lib/linkedin2.rb +10 -0
- data/linkedin.gemspec +27 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 940f99d965d7161ae9733d7020ae5d309c07c1ab
|
4
|
+
data.tar.gz: 1a52bf8d319dbe8cf70895125d6ae7769f2314ad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8169135bc4a73f41cacad9fe82ddd7baab77822d12b267508b7068d9dc96cf22ce3b0ee2666c1d2fcf3b77b4362431eaefe922cea8c4b28741faa81694dee4f7
|
7
|
+
data.tar.gz: 08c42010a9118a6585f527981ee60c88d91d80470165de558c45636d2df6a04acbe16d4436563660f3aed549247edb9ccb396141961d64f2349de27a8be0c08d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Bob Breznak
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# LinkedIn 2
|
2
|
+
|
3
|
+
A modernized LinkedIn Ruby client.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'linkedin'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install linkedin
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Client Configuration
|
22
|
+
|
23
|
+
Configure an instance directly with a hash:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = LinkedIn::Client.new key: <your-key>, secret: <your-secret>, redirect_uri: <your-callback>
|
27
|
+
```
|
28
|
+
|
29
|
+
Or configure an instance directly with the configure method:
|
30
|
+
```ruby
|
31
|
+
client = LinkedIn::Client.new
|
32
|
+
client.configure do |config|
|
33
|
+
config.key = <your-key>
|
34
|
+
end
|
35
|
+
client.key # => <your-key>
|
36
|
+
```
|
37
|
+
|
38
|
+
Or configure the gem with a hash:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
LinkedIn::Client.configure key: <your-key>, secret: <your-secret>, redirect_uri: <your-callback>
|
42
|
+
client = LinkedIn::Client.new
|
43
|
+
client.key # => <your-key>
|
44
|
+
```
|
45
|
+
|
46
|
+
Or configure the gem with a block:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
LinkedIn::Client.configure do |config|
|
50
|
+
config.key = '<your-key>'
|
51
|
+
end
|
52
|
+
client = LinkedIn::Client.new
|
53
|
+
client.key # => <your-key>
|
54
|
+
```
|
55
|
+
|
56
|
+
### Authentication
|
57
|
+
|
58
|
+
Following the [LinkedIn Authentication Documentation](http://developer.linkedin.com/documents/authentication):
|
59
|
+
|
60
|
+
*Step 1. Register your application*
|
61
|
+
|
62
|
+
Create a LinkedIn Account and register an application
|
63
|
+
|
64
|
+
*Step 2a. Generate Authorization Code by redirecting user to LinkedIn's authorization dialog*
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
# create a client and configure it with your :key, :secret and :redirect_uri. See "Client Configuration" above.
|
68
|
+
client.authorize_url # => A URI that will take a user to LinkedIn, ask them to login and redirect to the URI that you configured
|
69
|
+
```
|
70
|
+
|
71
|
+
*Step 2b. Request Access Token by exchanging the authorization_code for it*
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# create a client and configure it with your :key, :secret and :redirect_uri. See "Client Configuration" above.
|
75
|
+
client.request_access_token '<token-from-response>'
|
76
|
+
```
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
1. Fork it
|
81
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
82
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
83
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
84
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module LinkedIn
|
2
|
+
module API
|
3
|
+
module Authentication
|
4
|
+
attr_reader :state
|
5
|
+
attr_accessor :access_token
|
6
|
+
|
7
|
+
def authorize_url(params={})
|
8
|
+
params.reverse_merge! defaults(:scope, :state, :redirect_uri)
|
9
|
+
auth_code.authorize_url params
|
10
|
+
end
|
11
|
+
|
12
|
+
def request_access_token(authorization_code, params={})
|
13
|
+
raise Error::CSRF.new state, params[:state] if params[:state] && params[:state] != state
|
14
|
+
|
15
|
+
params.reverse_merge! defaults(:redirect_uri)
|
16
|
+
opts = { mode: :query, param_name: 'oauth2_access_token' }
|
17
|
+
|
18
|
+
token_response = auth_code.get_token authorization_code, params, opts
|
19
|
+
self.access_token = token_response.token
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'byebug'
|
2
|
+
|
3
|
+
module LinkedIn
|
4
|
+
class Client
|
5
|
+
include Configuration
|
6
|
+
include API::Authentication
|
7
|
+
|
8
|
+
def initialize(options={})
|
9
|
+
configure options
|
10
|
+
end
|
11
|
+
|
12
|
+
def connection
|
13
|
+
OAuth2::Client.new key, secret, oauth2_options
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def auth_code
|
19
|
+
connection.auth_code unless connection.nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
def oauth2_options
|
23
|
+
{ site: options[:api_host],
|
24
|
+
authorize_url: url_for(:authorize),
|
25
|
+
token_url: url_for(:access_token) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def url_for(option_key)
|
29
|
+
host = options[:auth_host]
|
30
|
+
path = options["#{option_key}_path".to_sym]
|
31
|
+
"#{host}#{path}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module LinkedIn
|
2
|
+
module Configuration
|
3
|
+
module ClassConfiguration
|
4
|
+
BASE_OPTIONS = {
|
5
|
+
authorize_path: '/uas/oauth2/authorization',
|
6
|
+
access_token_path: '/uas/oauth2/accessToken',
|
7
|
+
api_host: 'https://api.linkedin.com',
|
8
|
+
auth_host: 'https://www.linkedin.com',
|
9
|
+
|
10
|
+
key: nil,
|
11
|
+
secret: nil,
|
12
|
+
|
13
|
+
scope: 'r_basicprofile',
|
14
|
+
state: Utils.generate_random_state,
|
15
|
+
redirect_uri: 'http://localhost'
|
16
|
+
}
|
17
|
+
|
18
|
+
def options
|
19
|
+
@options ||= reset
|
20
|
+
end
|
21
|
+
|
22
|
+
def reset
|
23
|
+
@options = OpenStruct.new BASE_OPTIONS
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module InstanceConfiguration
|
28
|
+
def options
|
29
|
+
@options ||= reset
|
30
|
+
end
|
31
|
+
|
32
|
+
def reset
|
33
|
+
@options = self.class.options.clone
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module BaseConfiguration
|
38
|
+
def configure(options={}, &block)
|
39
|
+
self.options.marshal_load self.options.to_h.merge(options)
|
40
|
+
|
41
|
+
yield self if block_given?
|
42
|
+
|
43
|
+
self.options
|
44
|
+
end
|
45
|
+
|
46
|
+
def method_missing(method, *args, &block)
|
47
|
+
return self.options.send(method, *args, &block) if self.options.respond_to? method
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
51
|
+
def defaults(*keys)
|
52
|
+
options.to_h.slice keys
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
include BaseConfiguration
|
57
|
+
include InstanceConfiguration
|
58
|
+
|
59
|
+
def self.included(klass)
|
60
|
+
klass.extend BaseConfiguration
|
61
|
+
klass.extend ClassConfiguration
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module LinkedIn
|
2
|
+
class Error < StandardError; end
|
3
|
+
class CSRF < Error
|
4
|
+
def initialize(expected=nil, received=nil)
|
5
|
+
additional = "Excepted '#{expected}' but received '#{received}'" if expected
|
6
|
+
super "Response state did not match sent state. #{additional}"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/lib/linkedin2.rb
ADDED
data/linkedin.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'linkedin/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'linkedin2'
|
8
|
+
spec.version = LinkedIn::VERSION
|
9
|
+
spec.authors = ["Bob Breznak"]
|
10
|
+
spec.email = ["bob@evertrue.com"]
|
11
|
+
spec.description = %q{Ruby wrapper for the LinkedIn API}
|
12
|
+
spec.summary = %q{Ruby wrapper for the LinkedIn API}
|
13
|
+
spec.homepage = 'https://github.com/bobbrez/linkedin2'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'oauth2', '~> 0.9'
|
22
|
+
spec.add_dependency 'activesupport', '~> 4.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'byebug'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: linkedin2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bob Breznak
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oauth2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Ruby wrapper for the LinkedIn API
|
84
|
+
email:
|
85
|
+
- bob@evertrue.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/linkedin/api/authentication.rb
|
96
|
+
- lib/linkedin/client.rb
|
97
|
+
- lib/linkedin/configuration.rb
|
98
|
+
- lib/linkedin/error.rb
|
99
|
+
- lib/linkedin/utils.rb
|
100
|
+
- lib/linkedin/version.rb
|
101
|
+
- lib/linkedin2.rb
|
102
|
+
- linkedin.gemspec
|
103
|
+
homepage: https://github.com/bobbrez/linkedin2
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.0.0
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Ruby wrapper for the LinkedIn API
|
127
|
+
test_files: []
|
128
|
+
has_rdoc:
|