linkedin-bdigital 0.2.2

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.
Files changed (69) hide show
  1. data/.autotest +14 -0
  2. data/.document +5 -0
  3. data/.gitignore +25 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +20 -0
  6. data/README.markdown +78 -0
  7. data/Rakefile +41 -0
  8. data/VERSION +1 -0
  9. data/changelog.markdown +71 -0
  10. data/examples/authenticate.rb +21 -0
  11. data/examples/network.rb +12 -0
  12. data/examples/profile.rb +14 -0
  13. data/examples/status.rb +9 -0
  14. data/lib/linked_in/api_standard_profile_request.rb +17 -0
  15. data/lib/linked_in/authorization_helpers.rb +48 -0
  16. data/lib/linked_in/base.rb +13 -0
  17. data/lib/linked_in/birthdate.rb +21 -0
  18. data/lib/linked_in/client.rb +155 -0
  19. data/lib/linked_in/company.rb +11 -0
  20. data/lib/linked_in/connections.rb +16 -0
  21. data/lib/linked_in/country.rb +9 -0
  22. data/lib/linked_in/current_share.rb +56 -0
  23. data/lib/linked_in/education.rb +41 -0
  24. data/lib/linked_in/error.rb +21 -0
  25. data/lib/linked_in/group.rb +32 -0
  26. data/lib/linked_in/languages.rb +28 -0
  27. data/lib/linked_in/likes.rb +23 -0
  28. data/lib/linked_in/location.rb +13 -0
  29. data/lib/linked_in/message.rb +20 -0
  30. data/lib/linked_in/network.rb +12 -0
  31. data/lib/linked_in/patents.rb +42 -0
  32. data/lib/linked_in/people.rb +18 -0
  33. data/lib/linked_in/person.rb +7 -0
  34. data/lib/linked_in/phone_number.rb +29 -0
  35. data/lib/linked_in/position.rb +46 -0
  36. data/lib/linked_in/profile.rb +85 -0
  37. data/lib/linked_in/publications.rb +40 -0
  38. data/lib/linked_in/recipient.rb +7 -0
  39. data/lib/linked_in/recipients.rb +18 -0
  40. data/lib/linked_in/recommendations.rb +30 -0
  41. data/lib/linked_in/request_helpers.rb +78 -0
  42. data/lib/linked_in/short_profile.rb +13 -0
  43. data/lib/linked_in/skill.rb +33 -0
  44. data/lib/linked_in/to_xml_helpers.rb +53 -0
  45. data/lib/linked_in/update.rb +23 -0
  46. data/lib/linked_in/url_resource.rb +26 -0
  47. data/lib/linkedin.rb +81 -0
  48. data/linkedin.gemspec +49 -0
  49. data/spec/cases/client_spec.rb +230 -0
  50. data/spec/cases/linkedin_spec.rb +37 -0
  51. data/spec/cases/oauth_spec.rb +109 -0
  52. data/spec/client_shared_examples.rb +91 -0
  53. data/spec/fixtures/403.xml +7 -0
  54. data/spec/fixtures/404.xml +7 -0
  55. data/spec/fixtures/blank.xml +0 -0
  56. data/spec/fixtures/connections.xml +3733 -0
  57. data/spec/fixtures/likes.xml +18 -0
  58. data/spec/fixtures/mailbox_items.xml +16 -0
  59. data/spec/fixtures/network_status_with_group.xml +44 -0
  60. data/spec/fixtures/network_statuses.xml +317 -0
  61. data/spec/fixtures/picture_updates.xml +117 -0
  62. data/spec/fixtures/profile.xml +9 -0
  63. data/spec/fixtures/profile_full.xml +3909 -0
  64. data/spec/fixtures/profile_with_positions.xml +79 -0
  65. data/spec/fixtures/search.xml +538 -0
  66. data/spec/fixtures/shares.xml +12 -0
  67. data/spec/fixtures/status.xml +2 -0
  68. data/spec/spec_helper.rb +58 -0
  69. 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
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
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
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
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
@@ -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
@@ -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
@@ -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
+
@@ -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,13 @@
1
+ module LinkedIn
2
+ class Base
3
+
4
+ def self.from_xml(doc)
5
+ new(Nokogiri::XML(doc))
6
+ end
7
+
8
+ def initialize(doc)
9
+ @doc = doc
10
+ end
11
+
12
+ end
13
+ 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