linkedin 0.2.2 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/{spec/fixtures/blank.xml → .gemtest} +0 -0
  2. data/.gitignore +36 -21
  3. data/.rspec +3 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +6 -2
  6. data/Rakefile +9 -31
  7. data/changelog.markdown +1 -1
  8. data/lib/linked_in/api/query_methods.rb +49 -0
  9. data/lib/linked_in/api/update_methods.rb +54 -0
  10. data/lib/linked_in/client.rb +44 -147
  11. data/lib/linked_in/errors.rb +20 -0
  12. data/lib/linked_in/helpers/authorization.rb +67 -0
  13. data/lib/linked_in/helpers/request.rb +77 -0
  14. data/lib/linked_in/mash.rb +68 -0
  15. data/lib/linked_in/search.rb +34 -0
  16. data/lib/linked_in/version.rb +11 -0
  17. data/lib/linkedin.rb +4 -55
  18. data/linkedin.gemspec +26 -47
  19. data/spec/cases/client_spec.rb +260 -276
  20. data/spec/cases/linkedin_spec.rb +6 -6
  21. data/spec/cases/mash_spec.rb +85 -0
  22. data/spec/cases/oauth_spec.rb +146 -92
  23. data/spec/fixtures/cassette_library/LinkedIn_Client/_authorize_from_request.yml +28 -0
  24. data/spec/fixtures/cassette_library/LinkedIn_Client/_request_token.yml +28 -0
  25. data/spec/fixtures/cassette_library/LinkedIn_Client/_request_token/with_a_callback_url.yml +28 -0
  26. data/spec/fixtures/cassette_library/LinkedIn_Client/_request_token/with_default_options.yml +28 -0
  27. data/spec/helper.rb +30 -0
  28. metadata +139 -169
  29. data/VERSION +0 -1
  30. data/lib/linked_in/api_standard_profile_request.rb +0 -17
  31. data/lib/linked_in/authorization_helpers.rb +0 -48
  32. data/lib/linked_in/base.rb +0 -13
  33. data/lib/linked_in/birthdate.rb +0 -21
  34. data/lib/linked_in/company.rb +0 -11
  35. data/lib/linked_in/connections.rb +0 -16
  36. data/lib/linked_in/country.rb +0 -9
  37. data/lib/linked_in/current_share.rb +0 -56
  38. data/lib/linked_in/education.rb +0 -41
  39. data/lib/linked_in/error.rb +0 -21
  40. data/lib/linked_in/group.rb +0 -32
  41. data/lib/linked_in/languages.rb +0 -28
  42. data/lib/linked_in/likes.rb +0 -23
  43. data/lib/linked_in/location.rb +0 -13
  44. data/lib/linked_in/message.rb +0 -20
  45. data/lib/linked_in/network.rb +0 -12
  46. data/lib/linked_in/patents.rb +0 -42
  47. data/lib/linked_in/people.rb +0 -18
  48. data/lib/linked_in/person.rb +0 -7
  49. data/lib/linked_in/phone_number.rb +0 -29
  50. data/lib/linked_in/position.rb +0 -46
  51. data/lib/linked_in/profile.rb +0 -85
  52. data/lib/linked_in/publications.rb +0 -40
  53. data/lib/linked_in/recipient.rb +0 -7
  54. data/lib/linked_in/recipients.rb +0 -18
  55. data/lib/linked_in/recommendations.rb +0 -30
  56. data/lib/linked_in/short_profile.rb +0 -13
  57. data/lib/linked_in/skill.rb +0 -33
  58. data/lib/linked_in/to_xml_helpers.rb +0 -53
  59. data/lib/linked_in/update.rb +0 -23
  60. data/lib/linked_in/url_resource.rb +0 -26
  61. data/spec/fixtures/connections.xml +0 -3733
  62. data/spec/fixtures/error.xml +0 -7
  63. data/spec/fixtures/likes.xml +0 -18
  64. data/spec/fixtures/mailbox_items.xml +0 -16
  65. data/spec/fixtures/network_status_with_group.xml +0 -44
  66. data/spec/fixtures/network_statuses.xml +0 -317
  67. data/spec/fixtures/picture_updates.xml +0 -117
  68. data/spec/fixtures/profile.xml +0 -9
  69. data/spec/fixtures/profile_full.xml +0 -3906
  70. data/spec/fixtures/profile_with_positions.xml +0 -79
  71. data/spec/fixtures/search.xml +0 -538
  72. data/spec/fixtures/shares.xml +0 -12
  73. data/spec/fixtures/status.xml +0 -2
  74. data/spec/spec_helper.rb +0 -49
File without changes
data/.gitignore CHANGED
@@ -1,25 +1,40 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
1
+ *.gem
2
+ *.rbc
3
+ *.sw[a-p]
5
4
  *.tmproj
6
- tmtags
7
-
8
- ## EMACS
5
+ *.tmproject
6
+ *.un~
9
7
  *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
8
+ .DS_Store
9
+ .Spotlight-V100
10
+ .Trashes
11
+ ._*
12
+ .bundle
13
+ .config
14
+ .directory
15
+ .elc
16
+ .redcar
17
+ .yardoc
18
+ /.emacs.desktop
19
+ /.emacs.desktop.lock
20
+ Desktop.ini
21
+ Gemfile.lock
22
+ Icon?
23
+ InstalledFiles
24
+ Session.vim
25
+ Thumbs.db
26
+ \#*\#
27
+ _yardoc
28
+ auto-save-list
17
29
  coverage
18
- rdoc
30
+ doc/
31
+ lib/bundler/man
19
32
  pkg
20
-
21
- ## PROJECT::SPECIFIC
22
- examples/wynn.rb
23
-
24
- ## Bundler
25
- Gemfile.lock
33
+ pkg/*
34
+ rdoc
35
+ spec/reports
36
+ test/tmp
37
+ test/version_tmp
38
+ tmp
39
+ tmtags
40
+ tramp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - jruby
5
+ - ree
6
+ - ruby-head
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
- source :rubygems
1
+ source 'http://rubygems.org'
2
2
 
3
- gemspec
3
+ platforms :jruby do
4
+ gem 'jruby-openssl', '~> 0.7'
5
+ end
6
+
7
+ gemspec
data/Rakefile CHANGED
@@ -1,41 +1,19 @@
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
1
+ #!/usr/bin/env rake
9
2
 
10
-
11
- task :default => :spec
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
12
5
 
13
6
  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
7
+ RSpec::Core::RakeTask.new(:spec)
31
8
 
9
+ task :test => :spec
10
+ task :default => :spec
32
11
 
33
- require 'rake/rdoctask'
12
+ require 'rdoc/task'
13
+ require File.expand_path('../lib/linked_in/version', __FILE__)
34
14
  Rake::RDocTask.new do |rdoc|
35
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
36
-
37
15
  rdoc.rdoc_dir = 'rdoc'
38
- rdoc.title = "linkedin #{version}"
16
+ rdoc.title = "linkedin #{LinkedIn::VERSION::STRING}"
39
17
  rdoc.rdoc_files.include('README*')
40
18
  rdoc.rdoc_files.include('lib/**/*.rb')
41
19
  end
data/changelog.markdown CHANGED
@@ -1,6 +1,6 @@
1
1
  # Changelog
2
2
 
3
- ## 0.2.2 - March 3, 2010
3
+ ## 0.2.x - March x, 2010
4
4
 
5
5
  * Removed Crack as a dependency, Nokogiri FTW
6
6
 
@@ -0,0 +1,49 @@
1
+ module LinkedIn
2
+ module Api
3
+
4
+ module QueryMethods
5
+
6
+ def profile(options={})
7
+ path = person_path(options)
8
+ simple_query(path, options)
9
+ end
10
+
11
+ def connections(options={})
12
+ path = "#{person_path(options)}/connections"
13
+ simple_query(path, options)
14
+ end
15
+
16
+ def network_updates(options={})
17
+ path = "#{person_path(options)}/network/updates"
18
+ simple_query(path, options)
19
+ end
20
+
21
+ private
22
+
23
+ def simple_query(path, options={})
24
+ fields = options[:fields] || LinkedIn.default_profile_fields
25
+
26
+ if options[:public]
27
+ path +=":public"
28
+ elsif fields
29
+ path +=":(#{fields.map{ |f| f.to_s.gsub("_","-") }.join(',')})"
30
+ end
31
+
32
+ Mash.from_json(get(path))
33
+ end
34
+
35
+ def person_path(options)
36
+ path = "/people/"
37
+ if options[:id]
38
+ path += "id=#{options[:id]}"
39
+ elsif options[:url]
40
+ path += "url=#{CGI.escape(options[:url])}"
41
+ else
42
+ path += "~"
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,54 @@
1
+ module LinkedIn
2
+ module Api
3
+
4
+ module UpdateMethods
5
+
6
+ # def update_status(text)
7
+ # path = "/people/~/current-status"
8
+ # put(path, status_to_xml(text))
9
+ # end
10
+ #
11
+ # def share(options={})
12
+ # path = "/people/~/shares"
13
+ # defaults = { :visability => 'anyone' }
14
+ # post(path, share_to_xml(defaults.merge(options)))
15
+ # end
16
+ #
17
+ # def update_comment(network_key, comment)
18
+ # path = "/people/~/network/updates/key=#{network_key}/update-comments"
19
+ # post(path, comment_to_xml(comment))
20
+ # end
21
+ #
22
+ # def update_network(message)
23
+ # path = "/people/~/person-activities"
24
+ # post(path, network_update_to_xml(message))
25
+ # end
26
+ #
27
+ # def send_message(subject, body, recipient_paths)
28
+ # path = "/people/~/mailbox"
29
+ #
30
+ # message = LinkedIn::Message.new
31
+ # message.subject = subject
32
+ # message.body = body
33
+ # recipients = LinkedIn::Recipients.new
34
+ #
35
+ # recipients.recipients = recipient_paths.map do |profile_path|
36
+ # recipient = LinkedIn::Recipient.new
37
+ # recipient.person = LinkedIn::Person.new
38
+ # recipient.person.path = "/people/#{profile_path}"
39
+ # recipient
40
+ # end
41
+ # message.recipients = recipients
42
+ # post(path, message_to_xml(message)).code
43
+ # end
44
+ #
45
+ # def clear_status
46
+ # path = "/people/~/current-status"
47
+ # delete(path).code
48
+ # end
49
+ #
50
+
51
+ end
52
+
53
+ end
54
+ end
@@ -1,155 +1,52 @@
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
-
19
- def profile(options={})
20
- path = person_path(options)
21
- fields = options[:fields] || LinkedIn.default_profile_fields
22
-
23
- if options[:public]
24
- path +=":public"
25
- elsif fields
26
- path +=":(#{fields.map{ |f| f.to_s.gsub("_","-") }.join(',')})"
27
- end
28
-
29
- Profile.from_xml(get(path))
30
- end
31
-
32
- def connections(options={})
33
- path = "#{person_path(options)}/connections"
34
- fields = options[:fields] || LinkedIn.default_profile_fields
1
+ require 'linked_in/helpers/request'
2
+ require 'linked_in/helpers/authorization'
3
+ require 'linked_in/api/query_methods'
4
+ require 'linked_in/api/update_methods'
5
+ require 'linked_in/search'
35
6
 
36
- if options[:public]
37
- path +=":public"
38
- elsif fields
39
- path +=":(#{fields.map{ |f| f.to_s.gsub("_","-") }.join(',')})"
40
- end
7
+ require 'cgi'
41
8
 
42
- Connections.from_xml(get(path)).profiles
43
- end
44
-
45
- def search(options={})
46
- path = "/people"
47
- options = { :keywords => options } if options.is_a?(String)
48
- options = format_options_for_query(options)
49
-
50
- People.from_xml(get(to_uri(path, options)))
51
- end
52
-
53
- def current_status
54
- path = "/people/~/current-status"
55
- Nokogiri::XML(get(path)).xpath('//current-status').text
56
- end
57
-
58
- def update_status(text)
59
- path = "/people/~/current-status"
60
- put(path, status_to_xml(text))
61
- end
62
-
63
- def share(options={})
64
- path = "/people/~/shares"
65
- defaults = { :visability => 'anyone' }
66
- post(path, share_to_xml(defaults.merge(options)))
67
- end
68
-
69
- def update_comment(network_key, comment)
70
- path = "/people/~/network/updates/key=#{network_key}/update-comments"
71
- post(path, comment_to_xml(comment))
72
- end
73
-
74
- def like(network_key, is_liked=true)
75
- path = "/people/~/network/updates/key=#{network_key}/is-liked"
76
- put(path, is_liked_to_xml(is_liked))
77
- end
78
-
79
- def likes(network_key)
80
- path = "/people/~/network/updates/key=#{network_key}/likes"
81
- Likes.from_xml(get(path)).likes
82
- end
83
-
84
- def update_network(message)
85
- path = "/people/~/person-activities"
86
- post(path, network_update_to_xml(message))
87
- end
88
-
89
- def clear_status
90
- path = "/people/~/current-status"
91
- delete(path).code
92
- end
93
-
94
- def send_message(subject, body, recipient_paths)
95
- path = "/people/~/mailbox"
96
-
97
- message = LinkedIn::Message.new
98
- message.subject = subject
99
- message.body = body
100
- recipients = LinkedIn::Recipients.new
101
-
102
- recipients.recipients = recipient_paths.map do |profile_path|
103
- recipient = LinkedIn::Recipient.new
104
- recipient.person = LinkedIn::Person.new
105
- recipient.person.path = "/people/#{profile_path}"
106
- recipient
107
- end
108
-
109
- message.recipients = recipients
110
- post(path, message_to_xml(message)).code
111
- end
112
-
113
- def network_statuses(options={})
114
- options[:type] = 'STAT'
115
- network_updates(options)
116
- end
117
-
118
- def network_updates(options={})
119
- path = "/people/~/network"
120
- Network.from_xml(get(to_uri(path, options)))
121
- end
122
-
123
- # helpful in making authenticated calls and writing the
124
- # raw xml to a fixture file
125
- def write_fixture(path, filename)
126
- file = File.new("test/fixtures/#{filename}", "w")
127
- file.puts(access_token.get(path).body)
128
- file.close
129
- end
9
+ module LinkedIn
130
10
 
131
- private
11
+ class Client
12
+ include Helpers::Request
13
+ include Helpers::Authorization
14
+ include Api::QueryMethods
15
+ include Api::UpdateMethods
16
+ include Search
132
17
 
133
- def format_options_for_query(opts)
134
- opts.keys.each do |key|
135
- value = opts.delete(key)
136
- value = value.join("+") if value.is_a?(Array)
137
- value = value.gsub(" ", "+") if value.is_a?(String)
138
- opts[key.to_s.gsub("_","-")] = value
139
- end
140
- opts
141
- end
18
+ attr_reader :consumer_token, :consumer_secret, :consumer_options
142
19
 
143
- def person_path(options)
144
- path = "/people/"
145
- if options[:id]
146
- path += "id=#{options[:id]}"
147
- elsif options[:url]
148
- path += "url=#{CGI.escape(options[:url])}"
149
- else
150
- path += "~"
151
- end
152
- end
20
+ def initialize(ctoken=LinkedIn.token, csecret=LinkedIn.secret, options={})
21
+ @consumer_token = ctoken
22
+ @consumer_secret = csecret
23
+ @consumer_options = options
24
+ end
25
+
26
+ #
27
+ # def current_status
28
+ # path = "/people/~/current-status"
29
+ # Crack::XML.parse(get(path))['current_status']
30
+ # end
31
+ #
32
+ # def network_statuses(options={})
33
+ # options[:type] = 'STAT'
34
+ # network_updates(options)
35
+ # end
36
+ #
37
+ # def network_updates(options={})
38
+ # path = "/people/~/network"
39
+ # Network.from_xml(get(to_uri(path, options)))
40
+ # end
41
+ #
42
+ # # helpful in making authenticated calls and writing the
43
+ # # raw xml to a fixture file
44
+ # def write_fixture(path, filename)
45
+ # file = File.new("test/fixtures/#{filename}", "w")
46
+ # file.puts(access_token.get(path).body)
47
+ # file.close
48
+ # end
153
49
 
154
50
  end
51
+
155
52
  end