linkedin 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +55 -3
- data/VERSION +1 -1
- 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/examples/wynn.rb +10 -0
- data/lib/linked_in/client.rb +17 -7
- data/lib/linkedin.rb +1 -0
- metadata +11 -2
data/README.markdown
CHANGED
@@ -1,9 +1,61 @@
|
|
1
|
-
#
|
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
|
+
## Installation
|
6
|
+
|
7
|
+
sudo gem install gemcutter
|
8
|
+
gem tumble
|
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
|
+
|
2
54
|
|
3
|
-
Ruby wrapper for the [LinkedIn API](http://developer.linkedin.com)
|
4
55
|
|
5
56
|
## TODO
|
6
|
-
|
57
|
+
|
58
|
+
* Implement Messaging APIs
|
7
59
|
|
8
60
|
## Note on Patches/Pull Requests
|
9
61
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -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
|
data/examples/wynn.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'lib/linkedin'
|
2
|
+
c = LinkedIn::Client.new('shSB1C3K_Xq0xZ0U9w2VqSoKYhv2ISwFfNpdgrU4rGX3uiaNwbeCYifuGBlJvIc1', 'Xy8dprsITio46xj4jonNE27ZyNILSbHmMVDN1aEzRWVQk-eHJ2aXIkk8vwZUSgJd')
|
3
|
+
c.authorize_from_access("74f09d7b-3a41-4a01-8c6e-2b1072a046bc", "fcc8399e-3453-4328-9fe8-42021b73a110")
|
4
|
+
|
5
|
+
require 'lib/linkedin'
|
6
|
+
xml = File.open("test/fixtures/profile_full.xml", "r").read
|
7
|
+
p = LinkedIn::Profile.from_xml(xml)
|
8
|
+
|
9
|
+
|
10
|
+
|
data/lib/linked_in/client.rb
CHANGED
@@ -29,7 +29,7 @@ module LinkedIn
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# For web apps use params[:oauth_verifier], for desktop apps,
|
32
|
-
# use the verifier is the pin that
|
32
|
+
# use the verifier is the pin that LinkedIn gives users.
|
33
33
|
def authorize_from_request(rtoken, rsecret, verifier_or_pin)
|
34
34
|
request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret)
|
35
35
|
access_token = request_token.get_access_token(:oauth_verifier => verifier_or_pin)
|
@@ -88,7 +88,7 @@ module LinkedIn
|
|
88
88
|
if options[:public]
|
89
89
|
path +=":public"
|
90
90
|
else
|
91
|
-
path +=":(#{options[:fields].map{|f| f.to_s}.join(',')})"
|
91
|
+
path +=":(#{options[:fields].map{|f| f.to_s.gsub("_","-")}.join(',')})"
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -145,15 +145,25 @@ module LinkedIn
|
|
145
145
|
end
|
146
146
|
|
147
147
|
def raise_errors(response)
|
148
|
+
# Even if the XML answer contains the HTTP status code, LinkedIn also sets this code
|
149
|
+
# in the HTTP answer (thankfully).
|
148
150
|
case response.code.to_i
|
151
|
+
when 400
|
152
|
+
data = LinkedIn::Error.from_xml(response.body)
|
153
|
+
raise RateLimitExceeded.new(data), "(#{response.code}): #{response.message} - #{data.code if data}"
|
154
|
+
when 401
|
155
|
+
data = LinkedIn::Error.from_xml(response.body)
|
156
|
+
raise Unauthorized.new(data), "(#{response.code}): #{response.message} - #{data.code if data}"
|
157
|
+
when 403
|
158
|
+
data = LinkedIn::Error.from_xml(response.body)
|
159
|
+
raise General.new(data), "(#{response.code}): #{response.message} - #{data.code if data}"
|
160
|
+
when 404
|
161
|
+
raise NotFound, "(#{response.code}): #{response.message}"
|
162
|
+
when 500
|
163
|
+
raise InformLinkedIn, "LinkedIn had an internal error. Please let them know in the forum. (#{response.code}): #{response.message}"
|
149
164
|
when 502..503
|
150
165
|
raise Unavailable, "(#{response.code}): #{response.message}"
|
151
166
|
end
|
152
|
-
|
153
|
-
if response.body && response.body.include?("<error>")
|
154
|
-
error = LinkedIn::Error.from_xml(response.body)
|
155
|
-
Raise LinkedInError, "(#{error.status}): #{error.code} - #{error.message}"
|
156
|
-
end
|
157
167
|
end
|
158
168
|
|
159
169
|
def format_options_for_query(opts)
|
data/lib/linkedin.rb
CHANGED
@@ -38,6 +38,7 @@ require File.join(directory, 'linked_in', 'url_resource')
|
|
38
38
|
require File.join(directory, 'linked_in', 'company')
|
39
39
|
require File.join(directory, 'linked_in', 'country')
|
40
40
|
require File.join(directory, 'linked_in', 'education')
|
41
|
+
require File.join(directory, 'linked_in', 'error')
|
41
42
|
require File.join(directory, 'linked_in', 'location')
|
42
43
|
require File.join(directory, 'linked_in', 'position')
|
43
44
|
require File.join(directory, 'linked_in', 'profile')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linkedin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wynn Netherland
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-08 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -96,6 +96,11 @@ files:
|
|
96
96
|
- README.markdown
|
97
97
|
- Rakefile
|
98
98
|
- VERSION
|
99
|
+
- examples/authenticate.rb
|
100
|
+
- examples/network.rb
|
101
|
+
- examples/profile.rb
|
102
|
+
- examples/status.rb
|
103
|
+
- examples/wynn.rb
|
99
104
|
- lib/linked_in/api_standard_profile_request.rb
|
100
105
|
- lib/linked_in/client.rb
|
101
106
|
- lib/linked_in/company.rb
|
@@ -156,3 +161,7 @@ test_files:
|
|
156
161
|
- test/client_test.rb
|
157
162
|
- test/oauth_test.rb
|
158
163
|
- test/test_helper.rb
|
164
|
+
- examples/authenticate.rb
|
165
|
+
- examples/network.rb
|
166
|
+
- examples/profile.rb
|
167
|
+
- examples/status.rb
|