linkedin-bdigital 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +14 -0
- data/.document +5 -0
- data/.gitignore +25 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.markdown +78 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/changelog.markdown +71 -0
- data/examples/authenticate.rb +21 -0
- data/examples/network.rb +12 -0
- data/examples/profile.rb +14 -0
- data/examples/status.rb +9 -0
- data/lib/linked_in/api_standard_profile_request.rb +17 -0
- data/lib/linked_in/authorization_helpers.rb +48 -0
- data/lib/linked_in/base.rb +13 -0
- data/lib/linked_in/birthdate.rb +21 -0
- data/lib/linked_in/client.rb +155 -0
- data/lib/linked_in/company.rb +11 -0
- data/lib/linked_in/connections.rb +16 -0
- data/lib/linked_in/country.rb +9 -0
- data/lib/linked_in/current_share.rb +56 -0
- data/lib/linked_in/education.rb +41 -0
- data/lib/linked_in/error.rb +21 -0
- data/lib/linked_in/group.rb +32 -0
- data/lib/linked_in/languages.rb +28 -0
- data/lib/linked_in/likes.rb +23 -0
- data/lib/linked_in/location.rb +13 -0
- data/lib/linked_in/message.rb +20 -0
- data/lib/linked_in/network.rb +12 -0
- data/lib/linked_in/patents.rb +42 -0
- data/lib/linked_in/people.rb +18 -0
- data/lib/linked_in/person.rb +7 -0
- data/lib/linked_in/phone_number.rb +29 -0
- data/lib/linked_in/position.rb +46 -0
- data/lib/linked_in/profile.rb +85 -0
- data/lib/linked_in/publications.rb +40 -0
- data/lib/linked_in/recipient.rb +7 -0
- data/lib/linked_in/recipients.rb +18 -0
- data/lib/linked_in/recommendations.rb +30 -0
- data/lib/linked_in/request_helpers.rb +78 -0
- data/lib/linked_in/short_profile.rb +13 -0
- data/lib/linked_in/skill.rb +33 -0
- data/lib/linked_in/to_xml_helpers.rb +53 -0
- data/lib/linked_in/update.rb +23 -0
- data/lib/linked_in/url_resource.rb +26 -0
- data/lib/linkedin.rb +81 -0
- data/linkedin.gemspec +49 -0
- data/spec/cases/client_spec.rb +230 -0
- data/spec/cases/linkedin_spec.rb +37 -0
- data/spec/cases/oauth_spec.rb +109 -0
- data/spec/client_shared_examples.rb +91 -0
- data/spec/fixtures/403.xml +7 -0
- data/spec/fixtures/404.xml +7 -0
- data/spec/fixtures/blank.xml +0 -0
- data/spec/fixtures/connections.xml +3733 -0
- data/spec/fixtures/likes.xml +18 -0
- data/spec/fixtures/mailbox_items.xml +16 -0
- data/spec/fixtures/network_status_with_group.xml +44 -0
- data/spec/fixtures/network_statuses.xml +317 -0
- data/spec/fixtures/picture_updates.xml +117 -0
- data/spec/fixtures/profile.xml +9 -0
- data/spec/fixtures/profile_full.xml +3909 -0
- data/spec/fixtures/profile_with_positions.xml +79 -0
- data/spec/fixtures/search.xml +538 -0
- data/spec/fixtures/shares.xml +12 -0
- data/spec/fixtures/status.xml +2 -0
- data/spec/spec_helper.rb +58 -0
- metadata +179 -0
data/.autotest
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Autotest.add_hook(:initialize) do |at|
|
2
|
+
at.add_exception(".git")
|
3
|
+
end
|
4
|
+
|
5
|
+
Autotest.add_hook(:initialize) do |at|
|
6
|
+
at.clear_mappings
|
7
|
+
|
8
|
+
at.add_mapping %r%/^lib/(.*)\.rb$% do |_, m|
|
9
|
+
possible = File.basename(m[1])
|
10
|
+
files_matching %r%^test/.*(#{possible}_test|test_#{possible})\.rb$%
|
11
|
+
end
|
12
|
+
|
13
|
+
at.add_mapping(%r%^test/.*\.rb$%) {|filename, _| filename }
|
14
|
+
end
|
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
|
21
|
+
## PROJECT::SPECIFIC
|
22
|
+
examples/wynn.rb
|
23
|
+
|
24
|
+
## Bundler
|
25
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Wynn Netherland
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# LinkedIn
|
2
|
+
|
3
|
+
Ruby wrapper for the [LinkedIn API](http://developer.linkedin.com). Heavily inspired by [John Nunemaker's](http://github.com/jnunemaker) [Twitter gem](http://github.com/jnunemaker/twitter), the LinkedIn gem provides an easy-to-use wrapper for LinkedIn's Oauth/XML APIs.
|
4
|
+
|
5
|
+
Travis CI : [![Build Status](http://travis-ci.org/pengwynn/linkedin.png)](http://travis-ci.org/pengwynn/linkedin)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
[sudo] gem install linkedin
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
### Authenticate
|
14
|
+
|
15
|
+
LinkedIn's API uses Oauth for authentication. Luckily, the LinkedIn gem hides most of the gory details from you.
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
require 'linkedin'
|
19
|
+
|
20
|
+
# get your api keys at https://www.linkedin.com/secure/developer
|
21
|
+
client = LinkedIn::Client.new('your_consumer_key', 'your_consumer_secret')
|
22
|
+
rtoken = client.request_token.token
|
23
|
+
rsecret = client.request_token.secret
|
24
|
+
|
25
|
+
# to test from your desktop, open the following url in your browser
|
26
|
+
# and record the pin it gives you
|
27
|
+
client.request_token.authorize_url
|
28
|
+
=> "https://api.linkedin.com/uas/oauth/authorize?oauth_token=<generated_token>"
|
29
|
+
|
30
|
+
# then fetch your access keys
|
31
|
+
client.authorize_from_request(rtoken, rsecret, pin)
|
32
|
+
=> ["OU812", "8675309"] # <= save these for future requests
|
33
|
+
|
34
|
+
# or authorize from previously fetched access keys
|
35
|
+
c.authorize_from_access("OU812", "8675309")
|
36
|
+
|
37
|
+
# you're now free to move about the cabin, call any API method
|
38
|
+
|
39
|
+
### Profile examples
|
40
|
+
|
41
|
+
# get the profile for the authenticated user
|
42
|
+
client.profile
|
43
|
+
|
44
|
+
# get a profile for someone found in network via ID
|
45
|
+
client.profile(:id => 'gNma67_AdI')
|
46
|
+
|
47
|
+
# get a profile for someone via their public profile url
|
48
|
+
client.profile(:url => 'http://www.linkedin.com/in/netherland')
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
More examples in the [examples folder](http://github.com/pengwynn/linkedin/blob/master/examples).
|
53
|
+
|
54
|
+
For a nice example on using this in a [Rails App](http://pivotallabs.com/users/will/blog/articles/1096-linkedin-gem-for-a-web-app).
|
55
|
+
|
56
|
+
If you want to play with the LinkedIn api without using the gem, have a look at the [apigee LinkedIn console](http://app.apigee.com/console/linkedin).
|
57
|
+
|
58
|
+
## TODO
|
59
|
+
|
60
|
+
* Change to json api
|
61
|
+
* Update and correct test suite
|
62
|
+
* Change to Faraday for authentication
|
63
|
+
* Implement Messaging APIs
|
64
|
+
|
65
|
+
## Note on Patches/Pull Requests
|
66
|
+
|
67
|
+
* Fork the project.
|
68
|
+
* Make your feature addition or bug fix.
|
69
|
+
* Add tests for it. This is important so I don't break it in a
|
70
|
+
future version unintentionally.
|
71
|
+
* Commit, do not mess with rakefile, version, or history.
|
72
|
+
(if you want to have your own version, that is fine but
|
73
|
+
bump version in a commit by itself I can ignore when I pull)
|
74
|
+
* Send me a pull request. Bonus points for topic branches.
|
75
|
+
|
76
|
+
## Copyright
|
77
|
+
|
78
|
+
Copyright (c) 2009-11 [Wynn Netherland](http://wynnnetherland.com). See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
rescue LoadError
|
7
|
+
puts 'although not required, bundler is recommened for running the tests'
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
task :default => :spec
|
12
|
+
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
RSpec::Core::RakeTask.new do |t|
|
15
|
+
t.rspec_opts = ["--color", '--format doc']
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
begin
|
20
|
+
require 'rcov/rcovtask'
|
21
|
+
Rcov::RcovTask.new do |test|
|
22
|
+
test.libs << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
rescue LoadError
|
27
|
+
task :rcov do
|
28
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
require 'rake/rdoctask'
|
34
|
+
Rake::RDocTask.new do |rdoc|
|
35
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
36
|
+
|
37
|
+
rdoc.rdoc_dir = 'rdoc'
|
38
|
+
rdoc.title = "linkedin #{version}"
|
39
|
+
rdoc.rdoc_files.include('README*')
|
40
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
41
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
data/changelog.markdown
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.2.2 - March 3, 2010
|
4
|
+
|
5
|
+
* Removed Crack as a dependency, Nokogiri FTW
|
6
|
+
|
7
|
+
## 0.2.1 - March 1, 2010
|
8
|
+
|
9
|
+
* Big dependency clean up, only OAuth and Nokogiri are really needed.
|
10
|
+
|
11
|
+
* Use Nokogiri for xml generation (thanks Leonid Shevtsov - leonid-shevtsov)
|
12
|
+
|
13
|
+
* Like and Likes supported
|
14
|
+
|
15
|
+
* Escape querystring args
|
16
|
+
|
17
|
+
* General coding cleanup
|
18
|
+
|
19
|
+
* Added Languages, Skills, Publications, Patents and Phone Numbers (thanks Tadas Tamošauskas - medwezys)
|
20
|
+
|
21
|
+
* Extra fields added to profile (thanks Tadas Tamošauskas - medwezys)
|
22
|
+
|
23
|
+
* public\_profile\_field added to Profile (thanks troysteinbauer)
|
24
|
+
|
25
|
+
* Added recommendations (thanks Erol)
|
26
|
+
|
27
|
+
* Added current-share
|
28
|
+
|
29
|
+
* Added default\_profile\__fields config option
|
30
|
+
|
31
|
+
## 0.1.7 - February 5, 2010
|
32
|
+
|
33
|
+
* New group join status support JGRP from Terry Ray
|
34
|
+
|
35
|
+
## 0.1.6 - January 20, 2010
|
36
|
+
|
37
|
+
* Fixed bug with network status update connection collections - thanks Terry Ray
|
38
|
+
|
39
|
+
## 0.1.5 - January 13, 2010
|
40
|
+
|
41
|
+
* Added education and profile fields missing from updated LinkedIn docs
|
42
|
+
|
43
|
+
## 0.1.4 - January 13, 2010
|
44
|
+
|
45
|
+
* Applied patch for position end month/year from @holman
|
46
|
+
|
47
|
+
## 0.1.3 - December 24, 2009
|
48
|
+
|
49
|
+
* Added configure block for easier initialization of consumer token, secret
|
50
|
+
|
51
|
+
## 0.1.1 - December 8, 2009
|
52
|
+
|
53
|
+
* Applied patch from [nfo](http://github.com/nfo) to fix error handling
|
54
|
+
|
55
|
+
## 0.1.0 - November 25, 2009
|
56
|
+
|
57
|
+
* Network updates API support
|
58
|
+
|
59
|
+
* Search API support
|
60
|
+
|
61
|
+
* Updates API support
|
62
|
+
|
63
|
+
## 0.0.2 - November 25, 2009
|
64
|
+
|
65
|
+
* Swapped out Crack for ROXML for prettier object access
|
66
|
+
|
67
|
+
* Added more tests for Profile API
|
68
|
+
|
69
|
+
## 0.0.1 - November 24, 2009
|
70
|
+
|
71
|
+
* Initial release
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'linkedin'
|
3
|
+
|
4
|
+
# get your api keys at https://www.linkedin.com/secure/developer
|
5
|
+
client = LinkedIn::Client.new('your_consumer_key', 'your_consumer_secret')
|
6
|
+
rtoken = client.request_token.token
|
7
|
+
rsecret = client.request_token.secret
|
8
|
+
|
9
|
+
# to test from your desktop, open the following url in your browser
|
10
|
+
# and record the pin it gives you
|
11
|
+
client.request_token.authorize_url
|
12
|
+
=> "https://api.linkedin.com/uas/oauth/authorize?oauth_token=<generated_token>"
|
13
|
+
|
14
|
+
# then fetch your access keys
|
15
|
+
client.authorize_from_request(rtoken, rsecret, pin)
|
16
|
+
=> ["OU812", "8675309"] # <= save these for future requests
|
17
|
+
|
18
|
+
# or authorize from previously fetched access keys
|
19
|
+
c.authorize_from_access("OU812", "8675309")
|
20
|
+
|
21
|
+
# you're now free to move about the cabin, call any API method
|
data/examples/network.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# AUTHENTICATE FIRST found in examples/authenticate.rb
|
2
|
+
|
3
|
+
# client is a LinkedIn::Client
|
4
|
+
|
5
|
+
# get network updates for the authenticated user
|
6
|
+
client.network_updates
|
7
|
+
|
8
|
+
# get profile picture changes
|
9
|
+
client.network_updates(:type => 'PICT')
|
10
|
+
|
11
|
+
# view connections for the currently authenticated user
|
12
|
+
client.connections
|
data/examples/profile.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# AUTHENTICATE FIRST found in examples/authenticate.rb
|
2
|
+
|
3
|
+
# client is a LinkedIn::Client
|
4
|
+
|
5
|
+
# get the profile for the authenticated user
|
6
|
+
client.profile
|
7
|
+
|
8
|
+
# get a profile for someone found in network via ID
|
9
|
+
client.profile(:id => 'gNma67_AdI')
|
10
|
+
|
11
|
+
# get a profile for someone via their public profile url
|
12
|
+
client.profile(:url => 'http://www.linkedin.com/in/netherland')
|
13
|
+
|
14
|
+
|
data/examples/status.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# AUTHENTICATE FIRST found in examples/authenticate.rb
|
2
|
+
|
3
|
+
# client is a LinkedIn::Client
|
4
|
+
|
5
|
+
# update status for the authenticated user
|
6
|
+
client.update_status('is playing with the LinkedIn Ruby gem')
|
7
|
+
|
8
|
+
# clear status for the currently logged in user
|
9
|
+
client.clear_status
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module LinkedIn
|
2
|
+
class ApiStandardProfileRequest < LinkedIn::Base
|
3
|
+
|
4
|
+
def url
|
5
|
+
@doc.xpath("//api-standard-profile-request/url").text
|
6
|
+
end
|
7
|
+
|
8
|
+
# returning a hash should be ok, but suggestions are welcome
|
9
|
+
def headers
|
10
|
+
hash = {}
|
11
|
+
hash[:name] = @doc.xpath("//api-standard-profile-request/headers/http-header/name").text
|
12
|
+
hash[:value] = @doc.xpath("//api-standard-profile-request/headers/http-header/value").text
|
13
|
+
hash
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module LinkedIn
|
2
|
+
|
3
|
+
module AuthorizationHelpers
|
4
|
+
|
5
|
+
def consumer
|
6
|
+
@consumer ||= begin
|
7
|
+
options = { :site => 'https://api.linkedin.com' }.merge(@consumer_options)
|
8
|
+
::OAuth::Consumer.new(@ctoken, @csecret, options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_callback_url(url)
|
13
|
+
clear_request_token
|
14
|
+
request_token(:oauth_callback => url)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Note: If using oauth with a web app, be sure to provide :oauth_callback.
|
18
|
+
# Options:
|
19
|
+
# :oauth_callback => String, url that LinkedIn should redirect to
|
20
|
+
def request_token(options={})
|
21
|
+
@request_token ||= consumer.get_request_token(options)
|
22
|
+
end
|
23
|
+
|
24
|
+
# For web apps use params[:oauth_verifier], for desktop apps,
|
25
|
+
# use the verifier is the pin that LinkedIn gives users.
|
26
|
+
def authorize_from_request(rtoken, rsecret, verifier_or_pin)
|
27
|
+
request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret)
|
28
|
+
access_token = request_token.get_access_token(:oauth_verifier => verifier_or_pin)
|
29
|
+
@atoken, @asecret = access_token.token, access_token.secret
|
30
|
+
end
|
31
|
+
|
32
|
+
def access_token
|
33
|
+
@access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
|
34
|
+
end
|
35
|
+
|
36
|
+
def authorize_from_access(atoken, asecret)
|
37
|
+
@atoken, @asecret = atoken, asecret
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def clear_request_token
|
43
|
+
@request_token = nil
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module LinkedIn
|
2
|
+
class Birthdate < LinkedIn::Base
|
3
|
+
|
4
|
+
def year
|
5
|
+
@year ||= @doc.xpath("/person/date-of-birth/year").text.to_i
|
6
|
+
end
|
7
|
+
|
8
|
+
def day
|
9
|
+
@day ||= @doc.xpath("/person/date-of-birth/day").text.to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
def month
|
13
|
+
@month ||= @doc.xpath("/person/date-of-birth/month").text.to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_date
|
17
|
+
Date.civil(y=year,m=month,d=day)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|