cl_linkedin 0.2.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/.autotest +14 -0
- data/.document +5 -0
- data/.gitignore +25 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.markdown +80 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/changelog.markdown +76 -0
- data/examples/authenticate.rb +21 -0
- data/examples/network.rb +12 -0
- data/examples/profile.rb +12 -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 +154 -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/im_account.rb +28 -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 +94 -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/twitter_account.rb +28 -0
- data/lib/linked_in/update.rb +23 -0
- data/lib/linked_in/url_resource.rb +26 -0
- data/lib/linkedin.rb +83 -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.orig.rb +91 -0
- data/spec/client_shared_examples.rb +104 -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.orig.xml +3909 -0
- data/spec/fixtures/profile_full.xml +395 -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 +242 -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,80 @@
|
|
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 : [](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
|
+
Full request string for test XML data http://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,location,industry,distance,current-share,connections,num-connections,num-connections-capped,summary,specialties,proposal-comments,associations,honors,interests,positions,publications,patents,languages,skills,certifications,educations,three-current-positions,three-past-positions,num-recommenders,recommendations-received,phone-numbers,im-accounts,twitter-accounts,date-of-birth,main-address,member-url-resources,picture-url,site-standard-profile-request,api-public-profile-request,api-standard-profile-request,public-profile-url)
|
59
|
+
|
60
|
+
## TODO
|
61
|
+
|
62
|
+
* Change to json api
|
63
|
+
* Update and correct test suite
|
64
|
+
* Change to Faraday for authentication
|
65
|
+
* Implement Messaging APIs
|
66
|
+
|
67
|
+
## Note on Patches/Pull Requests
|
68
|
+
|
69
|
+
* Fork the project.
|
70
|
+
* Make your feature addition or bug fix.
|
71
|
+
* Add tests for it. This is important so I don't break it in a
|
72
|
+
future version unintentionally.
|
73
|
+
* Commit, do not mess with rakefile, version, or history.
|
74
|
+
(if you want to have your own version, that is fine but
|
75
|
+
bump version in a commit by itself I can ignore when I pull)
|
76
|
+
* Send me a pull request. Bonus points for topic branches.
|
77
|
+
|
78
|
+
## Copyright
|
79
|
+
|
80
|
+
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.3
|
data/changelog.markdown
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.2.3 - July 20, 2011
|
4
|
+
|
5
|
+
* Added twitter_accounts and profile fields missing from updated LinkedIn docs
|
6
|
+
* Added im_accounts and profile fields missing from LinkedIn docs
|
7
|
+
|
8
|
+
## 0.2.2 - March 3, 2010
|
9
|
+
|
10
|
+
* Removed Crack as a dependency, Nokogiri FTW
|
11
|
+
|
12
|
+
## 0.2.1 - March 1, 2010
|
13
|
+
|
14
|
+
* Big dependency clean up, only OAuth and Nokogiri are really needed.
|
15
|
+
|
16
|
+
* Use Nokogiri for xml generation (thanks Leonid Shevtsov - leonid-shevtsov)
|
17
|
+
|
18
|
+
* Like and Likes supported
|
19
|
+
|
20
|
+
* Escape querystring args
|
21
|
+
|
22
|
+
* General coding cleanup
|
23
|
+
|
24
|
+
* Added Languages, Skills, Publications, Patents and Phone Numbers (thanks Tadas Tamošauskas - medwezys)
|
25
|
+
|
26
|
+
* Extra fields added to profile (thanks Tadas Tamošauskas - medwezys)
|
27
|
+
|
28
|
+
* public\_profile\_field added to Profile (thanks troysteinbauer)
|
29
|
+
|
30
|
+
* Added recommendations (thanks Erol)
|
31
|
+
|
32
|
+
* Added current-share
|
33
|
+
|
34
|
+
* Added default\_profile\__fields config option
|
35
|
+
|
36
|
+
## 0.1.7 - February 5, 2010
|
37
|
+
|
38
|
+
* New group join status support JGRP from Terry Ray
|
39
|
+
|
40
|
+
## 0.1.6 - January 20, 2010
|
41
|
+
|
42
|
+
* Fixed bug with network status update connection collections - thanks Terry Ray
|
43
|
+
|
44
|
+
## 0.1.5 - January 13, 2010
|
45
|
+
|
46
|
+
* Added education and profile fields missing from updated LinkedIn docs
|
47
|
+
|
48
|
+
## 0.1.4 - January 13, 2010
|
49
|
+
|
50
|
+
* Applied patch for position end month/year from @holman
|
51
|
+
|
52
|
+
## 0.1.3 - December 24, 2009
|
53
|
+
|
54
|
+
* Added configure block for easier initialization of consumer token, secret
|
55
|
+
|
56
|
+
## 0.1.1 - December 8, 2009
|
57
|
+
|
58
|
+
* Applied patch from [nfo](http://github.com/nfo) to fix error handling
|
59
|
+
|
60
|
+
## 0.1.0 - November 25, 2009
|
61
|
+
|
62
|
+
* Network updates API support
|
63
|
+
|
64
|
+
* Search API support
|
65
|
+
|
66
|
+
* Updates API support
|
67
|
+
|
68
|
+
## 0.0.2 - November 25, 2009
|
69
|
+
|
70
|
+
* Swapped out Crack for ROXML for prettier object access
|
71
|
+
|
72
|
+
* Added more tests for Profile API
|
73
|
+
|
74
|
+
## 0.0.1 - November 24, 2009
|
75
|
+
|
76
|
+
* Initial release
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'cl_linkedin'
|
3
|
+
|
4
|
+
# get your api keys at https://www.linkedin.com/secure/developer
|
5
|
+
client = LinkedIn::Client.new('LinkedInAPIKey', 'LinkedInAPISecret')
|
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
|
+
client.authorize_from_access("", "")
|
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,12 @@
|
|
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')
|
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
|
@@ -0,0 +1,154 @@
|
|
1
|
+
module LinkedIn
|
2
|
+
class Client
|
3
|
+
include ToXmlHelpers
|
4
|
+
include RequestHelpers
|
5
|
+
include AuthorizationHelpers
|
6
|
+
|
7
|
+
attr_reader :ctoken, :csecret, :consumer_options
|
8
|
+
|
9
|
+
def initialize(ctoken=LinkedIn.token, csecret=LinkedIn.secret, options={})
|
10
|
+
opts = {
|
11
|
+
:request_token_path => "/uas/oauth/requestToken",
|
12
|
+
:access_token_path => "/uas/oauth/accessToken",
|
13
|
+
:authorize_path => "/uas/oauth/authorize"
|
14
|
+
}
|
15
|
+
@ctoken, @csecret, @consumer_options = ctoken, csecret, opts.merge(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def profile(options={})
|
19
|
+
path = person_path(options)
|
20
|
+
fields = options[:fields] || LinkedIn.default_profile_fields
|
21
|
+
|
22
|
+
if options[:public]
|
23
|
+
path +=":public"
|
24
|
+
elsif fields
|
25
|
+
path +=":(#{fields.map{ |f| f.to_s.gsub("_","-") }.join(',')})"
|
26
|
+
end
|
27
|
+
|
28
|
+
Profile.from_xml(get(path))
|
29
|
+
end
|
30
|
+
|
31
|
+
def connections(options={})
|
32
|
+
path = "#{person_path(options)}/connections"
|
33
|
+
fields = options[:fields] || LinkedIn.default_profile_fields
|
34
|
+
|
35
|
+
if options[:public]
|
36
|
+
path +=":public"
|
37
|
+
elsif fields
|
38
|
+
path +=":(#{fields.map{ |f| f.to_s.gsub("_","-") }.join(',')})"
|
39
|
+
end
|
40
|
+
|
41
|
+
Connections.from_xml(get(path)).profiles
|
42
|
+
end
|
43
|
+
|
44
|
+
def search(options={})
|
45
|
+
path = "/people"
|
46
|
+
options = { :keywords => options } if options.is_a?(String)
|
47
|
+
options = format_options_for_query(options)
|
48
|
+
|
49
|
+
People.from_xml(get(to_uri(path, options)))
|
50
|
+
end
|
51
|
+
|
52
|
+
def current_status
|
53
|
+
path = "/people/~/current-status"
|
54
|
+
Nokogiri::XML(get(path)).xpath('//current-status').text
|
55
|
+
end
|
56
|
+
|
57
|
+
def update_status(text)
|
58
|
+
path = "/people/~/current-status"
|
59
|
+
put(path, status_to_xml(text))
|
60
|
+
end
|
61
|
+
|
62
|
+
def share(options={})
|
63
|
+
path = "/people/~/shares"
|
64
|
+
defaults = { :visability => 'anyone' }
|
65
|
+
post(path, share_to_xml(defaults.merge(options)))
|
66
|
+
end
|
67
|
+
|
68
|
+
def update_comment(network_key, comment)
|
69
|
+
path = "/people/~/network/updates/key=#{network_key}/update-comments"
|
70
|
+
post(path, comment_to_xml(comment))
|
71
|
+
end
|
72
|
+
|
73
|
+
def like(network_key, is_liked=true)
|
74
|
+
path = "/people/~/network/updates/key=#{network_key}/is-liked"
|
75
|
+
put(path, is_liked_to_xml(is_liked))
|
76
|
+
end
|
77
|
+
|
78
|
+
def likes(network_key)
|
79
|
+
path = "/people/~/network/updates/key=#{network_key}/likes"
|
80
|
+
Likes.from_xml(get(path)).likes
|
81
|
+
end
|
82
|
+
|
83
|
+
def update_network(message)
|
84
|
+
path = "/people/~/person-activities"
|
85
|
+
post(path, network_update_to_xml(message))
|
86
|
+
end
|
87
|
+
|
88
|
+
def clear_status
|
89
|
+
path = "/people/~/current-status"
|
90
|
+
delete(path).code
|
91
|
+
end
|
92
|
+
|
93
|
+
def send_message(subject, body, recipient_paths)
|
94
|
+
path = "/people/~/mailbox"
|
95
|
+
|
96
|
+
message = LinkedIn::Message.new
|
97
|
+
message.subject = subject
|
98
|
+
message.body = body
|
99
|
+
recipients = LinkedIn::Recipients.new
|
100
|
+
|
101
|
+
recipients.recipients = recipient_paths.map do |profile_path|
|
102
|
+
recipient = LinkedIn::Recipient.new
|
103
|
+
recipient.person = LinkedIn::Person.new
|
104
|
+
recipient.person.path = "/people/#{profile_path}"
|
105
|
+
recipient
|
106
|
+
end
|
107
|
+
|
108
|
+
message.recipients = recipients
|
109
|
+
post(path, message_to_xml(message)).code
|
110
|
+
end
|
111
|
+
|
112
|
+
def network_statuses(options={})
|
113
|
+
options[:type] = 'STAT'
|
114
|
+
network_updates(options)
|
115
|
+
end
|
116
|
+
|
117
|
+
def network_updates(options={})
|
118
|
+
path = "/people/~/network"
|
119
|
+
Network.from_xml(get(to_uri(path, options)))
|
120
|
+
end
|
121
|
+
|
122
|
+
# helpful in making authenticated calls and writing the
|
123
|
+
# raw xml to a fixture file
|
124
|
+
def write_fixture(path, filename)
|
125
|
+
file = File.new("test/fixtures/#{filename}", "w")
|
126
|
+
file.puts(access_token.get(path).body)
|
127
|
+
file.close
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def format_options_for_query(opts)
|
133
|
+
opts.keys.each do |key|
|
134
|
+
value = opts.delete(key)
|
135
|
+
value = value.join("+") if value.is_a?(Array)
|
136
|
+
value = value.gsub(" ", "+") if value.is_a?(String)
|
137
|
+
opts[key.to_s.gsub("_","-")] = value
|
138
|
+
end
|
139
|
+
opts
|
140
|
+
end
|
141
|
+
|
142
|
+
def person_path(options)
|
143
|
+
path = "/people/"
|
144
|
+
if options[:id]
|
145
|
+
path += "id=#{options[:id]}"
|
146
|
+
elsif options[:url]
|
147
|
+
path += "url=#{CGI.escape(options[:url])}"
|
148
|
+
else
|
149
|
+
path += "~"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
end
|