linkedin 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
- - jruby
4
+ - 1.9.3
5
5
  - ree
6
- - ruby-head
6
+ - rbx
7
+ - rbx-2.0
@@ -2,7 +2,7 @@
2
2
 
3
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
4
 
5
- Travis CI : [![Build Status](http://travis-ci.org/pengwynn/linkedin.png)](http://travis-ci.org/pengwynn/linkedin)
5
+ Travis CI : [![Build Status](https://secure.travis-ci.org/pengwynn/linkedin.png)](http://travis-ci.org/pengwynn/linkedin)
6
6
 
7
7
  ## Installation
8
8
 
data/Rakefile CHANGED
File without changes
@@ -0,0 +1,6 @@
1
+ module LinkedIn
2
+ module Api
3
+ autoload :QueryMethods, "linked_in/api/query_methods"
4
+ autoload :UpdateMethods, "linked_in/api/update_methods"
5
+ end
6
+ end
@@ -1,9 +1,3 @@
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'
6
-
7
1
  require 'cgi'
8
2
 
9
3
  module LinkedIn
@@ -1,20 +1,19 @@
1
1
  module LinkedIn
2
-
3
- class LinkedInError < StandardError
4
- attr_reader :data
5
-
6
- def initialize(data)
7
- @data = data
8
- super
2
+ module Errors
3
+ class LinkedInError < StandardError
4
+ attr_reader :data
5
+ def initialize(data)
6
+ @data = data
7
+ super
8
+ end
9
9
  end
10
- end
11
10
 
12
- class RateLimitExceededError < LinkedInError; end
13
- class UnauthorizedError < LinkedInError; end
14
- class GeneralError < LinkedInError; end
11
+ class RateLimitExceededError < LinkedInError; end
12
+ class UnauthorizedError < LinkedInError; end
13
+ class GeneralError < LinkedInError; end
15
14
 
16
- class UnavailableError < StandardError; end
17
- class InformLinkedInError < StandardError; end
18
- class NotFoundError < StandardError; end
19
-
20
- end
15
+ class UnavailableError < StandardError; end
16
+ class InformLinkedInError < StandardError; end
17
+ class NotFoundError < StandardError; end
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ module LinkedIn
2
+ module Helpers
3
+ autoload :Authorization, "linked_in/helpers/authorization"
4
+ autoload :Request, "linked_in/helpers/request"
5
+ end
6
+ end
@@ -7,8 +7,8 @@ module LinkedIn
7
7
  :request_token_path => "/uas/oauth/requestToken",
8
8
  :access_token_path => "/uas/oauth/accessToken",
9
9
  :authorize_path => "/uas/oauth/authorize",
10
- :api_host => 'https://api.linkedin.com',
11
- :auth_host => 'https://www.linkedin.com'
10
+ :api_host => "https://api.linkedin.com",
11
+ :auth_host => "https://www.linkedin.com"
12
12
  }
13
13
 
14
14
  def consumer
@@ -48,6 +48,7 @@ module LinkedIn
48
48
  :request_token_url => full_oauth_url_for(:request_token, :api_host),
49
49
  :access_token_url => full_oauth_url_for(:access_token, :api_host),
50
50
  :authorize_url => full_oauth_url_for(:authorize, :auth_host),
51
+ :site => @consumer_options[:site] || @consumer_options[:api_host] || DEFAULT_OAUTH_OPTIONS[:api_host]
51
52
  }
52
53
  end
53
54
 
@@ -64,4 +65,4 @@ module LinkedIn
64
65
  end
65
66
 
66
67
  end
67
- end
68
+ end
@@ -43,16 +43,16 @@ module LinkedIn
43
43
  case response.code.to_i
44
44
  when 401
45
45
  data = Mash.from_json(response.body)
46
- raise UnauthorizedError.new(data), "(#{data.status}): #{data.message}"
46
+ raise LinkedIn::Errors::UnauthorizedError.new(data), "(#{data.status}): #{data.message}"
47
47
  when 400, 403
48
48
  data = Mash.from_json(response.body)
49
- raise GeneralError.new(data), "(#{data.status}): #{data.message}"
49
+ raise LinkedIn::Errors::GeneralError.new(data), "(#{data.status}): #{data.message}"
50
50
  when 404
51
- raise NotFoundError, "(#{response.code}): #{response.message}"
51
+ raise LinkedIn::Errors::NotFoundError, "(#{response.code}): #{response.message}"
52
52
  when 500
53
- raise InformLinkedInError, "LinkedIn had an internal error. Please let them know in the forum. (#{response.code}): #{response.message}"
53
+ raise LinkedIn::Errors::InformLinkedInError, "LinkedIn had an internal error. Please let them know in the forum. (#{response.code}): #{response.message}"
54
54
  when 502..503
55
- raise UnavailableError, "(#{response.code}): #{response.message}"
55
+ raise LinkedIn::Errors::UnavailableError, "(#{response.code}): #{response.message}"
56
56
  end
57
57
  end
58
58
 
@@ -74,4 +74,4 @@ module LinkedIn
74
74
  end
75
75
 
76
76
  end
77
- end
77
+ end
@@ -18,12 +18,12 @@ module LinkedIn
18
18
  def format_options_for_query(opts)
19
19
  opts.inject({}) do |list, kv|
20
20
  key, value = kv.first.to_s.gsub("_","-"), kv.last
21
- list[key] = sanatize_value(value)
21
+ list[key] = sanitize_value(value)
22
22
  list
23
23
  end
24
24
  end
25
25
 
26
- def sanatize_value(value)
26
+ def sanitize_value(value)
27
27
  value = value.join("+") if value.is_a?(Array)
28
28
  value = value.gsub(" ", "+") if value.is_a?(String)
29
29
  value
@@ -31,4 +31,4 @@ module LinkedIn
31
31
 
32
32
  end
33
33
 
34
- end
34
+ end
@@ -3,7 +3,7 @@ module LinkedIn
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
5
  MINOR = 3
6
- PATCH = 1
6
+ PATCH = 2
7
7
  PRE = nil
8
8
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
9
9
  end
@@ -22,9 +22,11 @@ module LinkedIn
22
22
  end
23
23
  end
24
24
 
25
+ autoload :Api, "linked_in/api"
26
+ autoload :Client, "linked_in/client"
27
+ autoload :Mash, "linked_in/mash"
28
+ autoload :Errors, "linked_in/errors"
29
+ autoload :Helpers, "linked_in/helpers"
30
+ autoload :Search, "linked_in/search"
31
+ autoload :Version, "linked_in/version"
25
32
  end
26
-
27
- require 'linked_in/mash'
28
- require 'linked_in/errors'
29
- require 'linked_in/client'
30
- require 'linked_in/version'
@@ -1,23 +1,20 @@
1
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
2
2
  require File.expand_path('../lib/linked_in/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.add_development_dependency 'rake', '~> 0.9'
6
- gem.add_development_dependency 'rdoc', '~> 3.8'
7
- gem.add_development_dependency 'rspec', '~> 2.6'
5
+ gem.add_dependency 'hashie', '~> 1.1.0'
6
+ gem.add_dependency 'multi_json', '~> 1.0.3'
7
+ gem.add_dependency 'oauth', '~> 0.4.5'
8
+ gem.add_development_dependency 'rake', '~> 0.9'
9
+ gem.add_development_dependency 'rdoc', '~> 3.8'
10
+ gem.add_development_dependency 'rspec', '~> 2.6'
8
11
  gem.add_development_dependency 'simplecov', '~> 0.4'
9
- gem.add_development_dependency 'vcr', '~> 1.10'
10
- gem.add_development_dependency 'webmock', '~> 1.6'
12
+ gem.add_development_dependency 'vcr', '~> 1.10'
13
+ gem.add_development_dependency 'webmock', '~> 1.7'
11
14
  gem.add_development_dependency 'yajl-ruby', '~> 0.8'
12
-
13
- gem.add_runtime_dependency 'hashie', '~> 1.0.0'
14
- gem.add_runtime_dependency 'multi_json', '~> 1.0.3'
15
- gem.add_runtime_dependency 'oauth', '~> 0.4.5'
16
-
17
15
  gem.authors = ["Wynn Netherland", "Josh Kalderimis"]
18
16
  gem.description = %q{Ruby wrapper for the LinkedIn API}
19
17
  gem.email = ['wynn.netherland@gmail.com', 'josh.kalderimis@gmail.com']
20
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
18
  gem.files = `git ls-files`.split("\n")
22
19
  gem.homepage = 'http://github.com/pengwynn/linkedin'
23
20
  gem.name = 'linkedin'
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ describe LinkedIn::Api do
4
+ before do
5
+ client.stub(:consumer).and_return(consumer)
6
+ client.authorize_from_access('atoken', 'asecret')
7
+ end
8
+
9
+ let(:client){LinkedIn::Client.new('token', 'secret')}
10
+ let(:consumer){OAuth::Consumer.new('token', 'secret', {:site => 'https://api.linkedin.com'})}
11
+
12
+ it "should be able to view the account profile" do
13
+ stub_request(:get, "https://api.linkedin.com/v1/people/~").to_return(:body => "{}")
14
+ client.profile.should be_an_instance_of(LinkedIn::Mash)
15
+ end
16
+
17
+ it "should be able to view public profiles" do
18
+ stub_request(:get, "https://api.linkedin.com/v1/people/id=123").to_return(:body => "{}")
19
+ client.profile(:id => 123).should be_an_instance_of(LinkedIn::Mash)
20
+ end
21
+
22
+ it "should be able to view connections" do
23
+ stub_request(:get, "https://api.linkedin.com/v1/people/~/connections").to_return(:body => "{}")
24
+ client.connections.should be_an_instance_of(LinkedIn::Mash)
25
+ end
26
+
27
+ it "should be able to view network_updates" do
28
+ stub_request(:get, "https://api.linkedin.com/v1/people/~/network/updates").to_return(:body => "{}")
29
+ client.network_updates.should be_an_instance_of(LinkedIn::Mash)
30
+ end
31
+
32
+ end
@@ -13,7 +13,7 @@ describe "LinkedIn::Client" do
13
13
  let(:consumer) { client.consumer }
14
14
 
15
15
  it "should return a configured OAuth consumer" do
16
- consumer.site.should == ''
16
+ consumer.site.should == 'https://api.linkedin.com'
17
17
  consumer.request_token_url.should == 'https://api.linkedin.com/uas/oauth/requestToken'
18
18
  consumer.access_token_url.should == 'https://api.linkedin.com/uas/oauth/accessToken'
19
19
  consumer.authorize_url.should == 'https://www.linkedin.com/uas/oauth/authorize'
@@ -29,6 +29,7 @@ describe "LinkedIn::Client" do
29
29
  end
30
30
 
31
31
  it "should return a configured OAuth consumer" do
32
+ consumer.site.should == 'https://api.josh.com'
32
33
  consumer.request_token_url.should == 'https://api.josh.com/uas/oauth/requestToken'
33
34
  consumer.access_token_url.should == 'https://api.josh.com/uas/oauth/accessToken'
34
35
  consumer.authorize_url.should == 'https://www.josh.com/uas/oauth/authorize'
@@ -45,6 +46,7 @@ describe "LinkedIn::Client" do
45
46
  end
46
47
 
47
48
  it "should return a configured OAuth consumer" do
49
+ consumer.site.should == 'https://api.linkedin.com'
48
50
  consumer.request_token_url.should == 'https://api.linkedin.com/secure/oauth/requestToken'
49
51
  consumer.access_token_url.should == 'https://api.linkedin.com/secure/oauth/accessToken'
50
52
  consumer.authorize_url.should == 'https://www.linkedin.com/secure/oauth/authorize'
@@ -61,6 +63,7 @@ describe "LinkedIn::Client" do
61
63
  end
62
64
 
63
65
  it "should return a configured OAuth consumer" do
66
+ consumer.site.should == 'https://api.linkedin.com'
64
67
  consumer.request_token_url.should == 'https://api.josh.com/secure/oauth/requestToken'
65
68
  consumer.access_token_url.should == 'https://api.josh.com/secure/oauth/accessToken'
66
69
  consumer.authorize_url.should == 'https://www.josh.com/secure/oauth/authorize'
@@ -75,6 +78,7 @@ describe "LinkedIn::Client" do
75
78
  end
76
79
 
77
80
  it "should return a configured OAuth consumer" do
81
+ consumer.site.should == 'https://api.josh.com'
78
82
  consumer.request_token_url.should == 'https://api.josh.com/uas/oauth/requestToken'
79
83
  consumer.access_token_url.should == 'https://api.josh.com/uas/oauth/accessToken'
80
84
  consumer.authorize_url.should == 'https://api.josh.com/uas/oauth/authorize'
metadata CHANGED
@@ -1,135 +1,139 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: linkedin
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.1
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.3.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Wynn Netherland
9
9
  - Josh Kalderimis
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-07-22 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rake
17
- requirement: &70124430784760 !ruby/object:Gem::Requirement
13
+
14
+ date: 2011-09-04 00:00:00 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: hashie
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
18
20
  none: false
19
- requirements:
21
+ requirements:
20
22
  - - ~>
21
- - !ruby/object:Gem::Version
22
- version: '0.9'
23
- type: :development
23
+ - !ruby/object:Gem::Version
24
+ version: 1.1.0
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
24
29
  prerelease: false
25
- version_requirements: *70124430784760
26
- - !ruby/object:Gem::Dependency
27
- name: rdoc
28
- requirement: &70124430783800 !ruby/object:Gem::Requirement
30
+ requirement: &id002 !ruby/object:Gem::Requirement
29
31
  none: false
30
- requirements:
32
+ requirements:
31
33
  - - ~>
32
- - !ruby/object:Gem::Version
33
- version: '3.8'
34
- type: :development
34
+ - !ruby/object:Gem::Version
35
+ version: 1.0.3
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: oauth
35
40
  prerelease: false
36
- version_requirements: *70124430783800
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
- requirement: &70124430783140 !ruby/object:Gem::Requirement
41
+ requirement: &id003 !ruby/object:Gem::Requirement
40
42
  none: false
41
- requirements:
43
+ requirements:
42
44
  - - ~>
43
- - !ruby/object:Gem::Version
44
- version: '2.6'
45
- type: :development
45
+ - !ruby/object:Gem::Version
46
+ version: 0.4.5
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rake
46
51
  prerelease: false
47
- version_requirements: *70124430783140
48
- - !ruby/object:Gem::Dependency
49
- name: simplecov
50
- requirement: &70124430782600 !ruby/object:Gem::Requirement
52
+ requirement: &id004 !ruby/object:Gem::Requirement
51
53
  none: false
52
- requirements:
54
+ requirements:
53
55
  - - ~>
54
- - !ruby/object:Gem::Version
55
- version: '0.4'
56
+ - !ruby/object:Gem::Version
57
+ version: "0.9"
56
58
  type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rdoc
57
62
  prerelease: false
58
- version_requirements: *70124430782600
59
- - !ruby/object:Gem::Dependency
60
- name: vcr
61
- requirement: &70124430782100 !ruby/object:Gem::Requirement
63
+ requirement: &id005 !ruby/object:Gem::Requirement
62
64
  none: false
63
- requirements:
65
+ requirements:
64
66
  - - ~>
65
- - !ruby/object:Gem::Version
66
- version: '1.10'
67
+ - !ruby/object:Gem::Version
68
+ version: "3.8"
67
69
  type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
68
73
  prerelease: false
69
- version_requirements: *70124430782100
70
- - !ruby/object:Gem::Dependency
71
- name: webmock
72
- requirement: &70124430781480 !ruby/object:Gem::Requirement
74
+ requirement: &id006 !ruby/object:Gem::Requirement
73
75
  none: false
74
- requirements:
76
+ requirements:
75
77
  - - ~>
76
- - !ruby/object:Gem::Version
77
- version: '1.6'
78
+ - !ruby/object:Gem::Version
79
+ version: "2.6"
78
80
  type: :development
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: simplecov
79
84
  prerelease: false
80
- version_requirements: *70124430781480
81
- - !ruby/object:Gem::Dependency
82
- name: yajl-ruby
83
- requirement: &70124430799940 !ruby/object:Gem::Requirement
85
+ requirement: &id007 !ruby/object:Gem::Requirement
84
86
  none: false
85
- requirements:
87
+ requirements:
86
88
  - - ~>
87
- - !ruby/object:Gem::Version
88
- version: '0.8'
89
+ - !ruby/object:Gem::Version
90
+ version: "0.4"
89
91
  type: :development
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: vcr
90
95
  prerelease: false
91
- version_requirements: *70124430799940
92
- - !ruby/object:Gem::Dependency
93
- name: hashie
94
- requirement: &70124430799380 !ruby/object:Gem::Requirement
96
+ requirement: &id008 !ruby/object:Gem::Requirement
95
97
  none: false
96
- requirements:
98
+ requirements:
97
99
  - - ~>
98
- - !ruby/object:Gem::Version
99
- version: 1.0.0
100
- type: :runtime
100
+ - !ruby/object:Gem::Version
101
+ version: "1.10"
102
+ type: :development
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: webmock
101
106
  prerelease: false
102
- version_requirements: *70124430799380
103
- - !ruby/object:Gem::Dependency
104
- name: multi_json
105
- requirement: &70124430798740 !ruby/object:Gem::Requirement
107
+ requirement: &id009 !ruby/object:Gem::Requirement
106
108
  none: false
107
- requirements:
109
+ requirements:
108
110
  - - ~>
109
- - !ruby/object:Gem::Version
110
- version: 1.0.3
111
- type: :runtime
111
+ - !ruby/object:Gem::Version
112
+ version: "1.7"
113
+ type: :development
114
+ version_requirements: *id009
115
+ - !ruby/object:Gem::Dependency
116
+ name: yajl-ruby
112
117
  prerelease: false
113
- version_requirements: *70124430798740
114
- - !ruby/object:Gem::Dependency
115
- name: oauth
116
- requirement: &70124430798100 !ruby/object:Gem::Requirement
118
+ requirement: &id010 !ruby/object:Gem::Requirement
117
119
  none: false
118
- requirements:
120
+ requirements:
119
121
  - - ~>
120
- - !ruby/object:Gem::Version
121
- version: 0.4.5
122
- type: :runtime
123
- prerelease: false
124
- version_requirements: *70124430798100
122
+ - !ruby/object:Gem::Version
123
+ version: "0.8"
124
+ type: :development
125
+ version_requirements: *id010
125
126
  description: Ruby wrapper for the LinkedIn API
126
- email:
127
+ email:
127
128
  - wynn.netherland@gmail.com
128
129
  - josh.kalderimis@gmail.com
129
130
  executables: []
131
+
130
132
  extensions: []
133
+
131
134
  extra_rdoc_files: []
132
- files:
135
+
136
+ files:
133
137
  - .autotest
134
138
  - .document
135
139
  - .gemtest
@@ -145,19 +149,20 @@ files:
145
149
  - examples/network.rb
146
150
  - examples/profile.rb
147
151
  - examples/status.rb
152
+ - lib/linked_in/api.rb
148
153
  - lib/linked_in/api/query_methods.rb
149
154
  - lib/linked_in/api/update_methods.rb
150
155
  - lib/linked_in/client.rb
151
156
  - lib/linked_in/errors.rb
157
+ - lib/linked_in/helpers.rb
152
158
  - lib/linked_in/helpers/authorization.rb
153
159
  - lib/linked_in/helpers/request.rb
154
160
  - lib/linked_in/mash.rb
155
- - lib/linked_in/request_helpers.rb
156
161
  - lib/linked_in/search.rb
157
162
  - lib/linked_in/version.rb
158
163
  - lib/linkedin.rb
159
164
  - linkedin.gemspec
160
- - spec/cases/client_spec.rb
165
+ - spec/cases/api_spec.rb
161
166
  - spec/cases/linkedin_spec.rb
162
167
  - spec/cases/mash_spec.rb
163
168
  - spec/cases/oauth_spec.rb
@@ -168,30 +173,33 @@ files:
168
173
  - spec/helper.rb
169
174
  homepage: http://github.com/pengwynn/linkedin
170
175
  licenses: []
176
+
171
177
  post_install_message:
172
178
  rdoc_options: []
173
- require_paths:
179
+
180
+ require_paths:
174
181
  - lib
175
- required_ruby_version: !ruby/object:Gem::Requirement
182
+ required_ruby_version: !ruby/object:Gem::Requirement
176
183
  none: false
177
- requirements:
178
- - - ! '>='
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
- required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: "0"
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
189
  none: false
183
- requirements:
184
- - - ! '>='
185
- - !ruby/object:Gem::Version
186
- version: '0'
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: "0"
187
194
  requirements: []
195
+
188
196
  rubyforge_project:
189
- rubygems_version: 1.8.5
197
+ rubygems_version: 1.8.10
190
198
  signing_key:
191
199
  specification_version: 3
192
200
  summary: Ruby wrapper for the LinkedIn API
193
- test_files:
194
- - spec/cases/client_spec.rb
201
+ test_files:
202
+ - spec/cases/api_spec.rb
195
203
  - spec/cases/linkedin_spec.rb
196
204
  - spec/cases/mash_spec.rb
197
205
  - spec/cases/oauth_spec.rb
@@ -1,76 +0,0 @@
1
- module LinkedIn
2
-
3
- module RequestHelpers
4
-
5
- def get(path, options={})
6
- path = "/v1#{path}"
7
- response = access_token.get(path, options)
8
- raise_errors(response)
9
- response.body
10
- end
11
-
12
- def post(path, body='', options={})
13
- path = "/v1#{path}"
14
- default_options = { 'Content-Type' => 'application/xml' }
15
- response = access_token.post(path, body, default_options.merge(options))
16
- raise_errors(response)
17
- response
18
- end
19
-
20
- def put(path, body, options={})
21
- path = "/v1#{path}"
22
- response = access_token.put(path, body, options)
23
- raise_errors(response)
24
- response
25
- end
26
-
27
- def delete(path, options={})
28
- path = "/v1#{path}"
29
- response = access_token.delete(path, options)
30
- raise_errors(response)
31
- response
32
- end
33
-
34
- private
35
-
36
- def raise_errors(response)
37
- # Even if the XML answer contains the HTTP status code, LinkedIn also sets this code
38
- # in the HTTP answer (thankfully).
39
- case response.code.to_i
40
- when 400
41
- data = LinkedIn::Error.from_xml(response.body)
42
- raise RateLimitExceeded.new(data), "(#{response.code}): #{response.message} - #{data.code if data}"
43
- when 401
44
- data = LinkedIn::Error.from_xml(response.body)
45
- raise Unauthorized.new(data), "(#{response.code}): #{response.message} - #{data.code if data}"
46
- when 403
47
- data = LinkedIn::Error.from_xml(response.body)
48
- raise General.new(data), "(#{response.code}): #{response.message} - #{data.code if data}"
49
- when 404
50
- raise NotFound, "(#{response.code}): #{response.message}"
51
- when 500
52
- raise InformLinkedIn, "LinkedIn had an internal error. Please let them know in the forum. (#{response.code}): #{response.message}"
53
- when 502..503
54
- raise Unavailable, "(#{response.code}): #{response.message}"
55
- end
56
- end
57
-
58
- def to_query(options)
59
- query_string = options.inject([]) do |collection, opt|
60
- collection << "#{opt[0]}=#{opt[1]}"
61
- collection
62
- end * '&'
63
- URI.escape(query_string)
64
- end
65
-
66
- def to_uri(path, options)
67
- uri = URI.parse(path)
68
-
69
- if options && options != {}
70
- uri.query = to_query(options)
71
- end
72
- uri.to_s
73
- end
74
- end
75
-
76
- end
@@ -1,265 +0,0 @@
1
- require 'helper'
2
-
3
- describe LinkedIn::Client do
4
-
5
- # context "when hitting the LinkedIn API" do
6
- #
7
- # before(:each) do
8
- # LinkedIn.token = nil
9
- # LinkedIn.secret = nil
10
- # LinkedIn.default_profile_fields = nil
11
- # end
12
- #
13
- # let(:client) do
14
- # client = LinkedIn::Client.new('token', 'secret')
15
- # consumer = OAuth::Consumer.new('token', 'secret', {:site => 'https://api.linkedin.com'})
16
- # client.stub(:consumer).and_return(consumer)
17
- # client.authorize_from_access('atoken', 'asecret')
18
- # client
19
- # end
20
- #
21
- # it "should retrieve a profile for the authenticated user" do
22
- # stub_get("/v1/people/~", "profile_full.xml")
23
- # client.profile.first_name.should == 'Wynn'
24
- # client.profile.last_name.should == 'Netherland'
25
- # end
26
- #
27
- # it "should retrieve location information" do
28
- # stub_get("/v1/people/~", "profile_full.xml")
29
- # client.profile.location.name.should == 'Dallas/Fort Worth Area'
30
- # client.profile.location.country.should == 'us'
31
- # end
32
- #
33
- # it "should retrieve positions from a profile" do
34
- # stub_get("/v1/people/~", "profile_full.xml")
35
- #
36
- # client.profile.positions.size.should == 4
37
- # client.profile.positions.first.company.name.should == 'Orrka'
38
- # client.profile.positions.first.is_current.should == 'true'
39
- #
40
- # hp = client.profile.positions[2]
41
- # hp.title.should == 'Solution Architect'
42
- # hp.id.should == '4891362'
43
- # hp.start_month.should == 10
44
- # hp.start_year.should == 2004
45
- # hp.end_month.should == 6
46
- # hp.end_year.should == 2007
47
- # hp.is_current.should == 'false'
48
- # end
49
- #
50
- # it "should retrieve education information from a profile" do
51
- # stub_get("/v1/people/~", "profile_full.xml")
52
- #
53
- # education = client.profile.educations.first
54
- # education.start_month.should == 8
55
- # education.start_year.should == 1994
56
- # education.end_month.should == 5
57
- # education.end_year.should == 1998
58
- # end
59
- #
60
- # it "should retrieve information about a profiles connections" do
61
- # stub_get("/v1/people/~", "profile_full.xml")
62
- #
63
- # client.profile.connections.size.should == 146
64
- # client.profile.connections.first.first_name.should == "Ali"
65
- # end
66
- #
67
- # it "should retrieve a profiles member_url_resources" do
68
- # stub_get("/v1/people/~", "profile_full.xml")
69
- #
70
- # client.profile.member_url_resources.size.should == 2
71
- # client.profile.member_url_resources.first.url.should == 'http://orrka.com'
72
- # client.profile.member_url_resources.first.name.should == 'My Company'
73
- # end
74
- #
75
- # it "should retrieve a profiles connections api_standard_profile_request" do
76
- # stub_get("/v1/people/~", "profile_full.xml")
77
- #
78
- # p1 = client.profile.connections.first
79
- # p1.api_standard_profile_request.url.should == 'http://api.linkedin.com/v1/people/3YNlBdusZ5:full'
80
- # p1.api_standard_profile_request.headers[:name].should == 'x-li-auth-token'
81
- # p1.api_standard_profile_request.headers[:value].should == 'name:lui9'
82
- # end
83
- #
84
- # it "should retrieve a profile for a member by id" do
85
- # stub_get("/v1/people/id=gNma67_AdI", "profile.xml")
86
- #
87
- # profile = client.profile(:id => "gNma67_AdI")
88
- # profile.first_name.should == 'Wynn'
89
- # end
90
- #
91
- # it "should retrieve a site_standard_profile_request" do
92
- # stub_get("/v1/people/~", "profile.xml")
93
- #
94
- # client.profile.site_standard_profile_request.should == "http://www.linkedin.com/profile?viewProfile=&key=3559698&authToken=yib-&authType=name"
95
- # end
96
- #
97
- # it "should retrieve a profile for a member by url" do
98
- # stub_get("/v1/people/url=http%3A%2F%2Fwww.linkedin.com%2Fin%2Fnetherland", "profile.xml")
99
- #
100
- # profile = client.profile(:url => "http://www.linkedin.com/in/netherland")
101
- # profile.last_name.should == 'Netherland'
102
- # end
103
- #
104
- # it "should accept field selectors when retrieving a profile" do
105
- # stub_get("/v1/people/~:(first-name,last-name)", "profile.xml")
106
- #
107
- # profile = client.profile(:fields => [:first_name, :last_name])
108
- # profile.first_name.should == 'Wynn'
109
- # profile.last_name.should == 'Netherland'
110
- # end
111
- #
112
- # it "should retrieve connections for the authenticated user" do
113
- # stub_get("/v1/people/~/connections", "connections.xml")
114
- #
115
- # cons = client.connections
116
- # cons.size.should == 146
117
- # cons.last.last_name.should == 'Yuchnewicz'
118
- # end
119
- #
120
- # it "should perform a search by keyword" do
121
- # stub_get("/v1/people?keywords=github", "search.xml")
122
- #
123
- # results = client.search(:keywords => 'github')
124
- # results.start.should == 0
125
- # results.count.should == 10
126
- # results.profiles.first.first_name.should == 'Zach'
127
- # results.profiles.first.last_name.should == 'Inglis'
128
- # end
129
- #
130
- # it "should perform a search by multiple keywords" do
131
- # stub_get("/v1/people?keywords=ruby+rails", "search.xml")
132
- #
133
- # results = client.search(:keywords => ["ruby", "rails"])
134
- # results.start.should == 0
135
- # results.count.should == 10
136
- # results.profiles.first.first_name.should == 'Zach'
137
- # results.profiles.first.last_name.should == 'Inglis'
138
- # end
139
- #
140
- # it "should perform a search by name" do
141
- # stub_get("/v1/people?name=Zach+Inglis", "search.xml")
142
- #
143
- # results = client.search(:name => "Zach Inglis")
144
- # results.start.should == 0
145
- # results.count.should == 10
146
- # results.profiles.first.first_name.should == 'Zach'
147
- # results.profiles.first.last_name.should == 'Inglis'
148
- # end
149
- #
150
- # it "should update a user's current status" do
151
- # stub_put("/v1/people/~/current-status", "blank.xml")
152
- #
153
- # client.update_status("Testing out the LinkedIn API").code.should == "200"
154
- # end
155
- #
156
- # it "should post to a user's network stream" do
157
- # stub_post("/v1/people/~/person-activities", "blank.xml")
158
- #
159
- # client.update_network("Testing out the LinkedIn API").code.should == "201"
160
- # end
161
- #
162
- # it "should clear a user's current status" do
163
- # stub_delete("/v1/people/~/current-status", "blank.xml")
164
- #
165
- # client.clear_status.should == "200"
166
- # end
167
- #
168
- # it "should retrieve the authenticated user's current status" do
169
- # stub_get("/v1/people/~/current-status", "status.xml")
170
- #
171
- # client.current_status.should == "New blog post: What makes a good API wrapper? http://wynnnetherland.com/2009/11/what-makes-a-good-api-wrapper/"
172
- # end
173
- #
174
- # it "should retrieve status updates for the authenticated user's network" do
175
- # stub_get("/v1/people/~/network?type=STAT", "network_statuses.xml")
176
- #
177
- # stats = client.network_statuses
178
- # stats.updates.first.timestamp.should == 1259179809524
179
- # stats.updates.first.profile.id.should == "19408512"
180
- # stats.updates.first.profile.first_name.should == 'Vahid'
181
- # stats.updates.first.profile.connections.first.id.should == "28072758"
182
- # stats.updates.first.profile.connections.first.last_name.should == 'Varone'
183
- # end
184
- #
185
- # it "should retrieve network updates" do
186
- # stub_get("/v1/people/~/network?type=PICT", "picture_updates.xml")
187
- #
188
- # stats = client.network_updates(:type => "PICT")
189
- # stats.updates.size.should == 4
190
- # stats.updates.last.profile.headline.should == "Creative Director for Intridea"
191
- # end
192
- #
193
- # it "should send a message to recipients" do
194
- # stub_post("/v1/people/~/mailbox", "mailbox_items.xml")
195
- #
196
- # recipients = ["~", "abcdefg"]
197
- # subject = "Congratulations on your new position."
198
- # body = "You're certainly the best person for the job!"
199
- #
200
- # client.send_message(subject, body, recipients).should == "201"
201
- #
202
- # expect_post("/v1/people/~/mailbox", "mailbox_items.xml")
203
- # end
204
- #
205
- # it "should share a link" do
206
- # stub_post("/v1/people/~/shares", "blank.xml")
207
- #
208
- # client.share({
209
- # :comment => "Testing out the LinkedIn API",
210
- # :title => "Share",
211
- # :url => "http://www.linkedin.com",
212
- # :image_url => "http://www.linkedin.com/pretty_logo.jpg"
213
- # }).code.should == "201"
214
- #
215
- # expect_post("/v1/people/~/shares", "shares.xml")
216
- # end
217
- #
218
- # it "should retrieve language information from a profile" do
219
- # stub_get("/v1/people/~", "profile_full.xml")
220
- #
221
- # language = client.profile.languages.last
222
- # language.name.should == "Klingon"
223
- # language.id.to_i.should == 72
224
- # end
225
- #
226
- # it "should retrieve skills from a profile" do
227
- # stub_get("/v1/people/~", "profile_full.xml")
228
- #
229
- # skill = client.profile.skills.last
230
- # skill.name.should == "Union negotiations"
231
- # skill.id.to_i.should == 38
232
- # end
233
- #
234
- # it "should retrieve phone_number from a profile" do
235
- # stub_get("/v1/people/~", "profile_full.xml")
236
- #
237
- # pn = client.profile.phone_numbers.last
238
- #
239
- # pn.phone_type.should == "mobile"
240
- # pn.phone_number.should == "+444444444444"
241
- # end
242
- #
243
- # it "should retrieve publications from a profile" do
244
- # stub_get("/v1/people/~", "profile_full.xml")
245
- #
246
- # publication = client.profile.publications.last
247
- #
248
- # publication.id.to_i.should == 31
249
- # publication.title.should == "How to host an awesome podcast"
250
- # publication.date.should == Date.civil(y=2006,m=8,d=1)
251
- # end
252
- #
253
- # it "should retrieve patents from a profile" do
254
- # stub_get("/v1/people/~", "profile_full.xml")
255
- #
256
- # patent = client.profile.patents.last
257
- #
258
- # patent.id.to_i.should == 51
259
- # patent.title.should == "Time machine"
260
- # patent.date.should == Date.civil(y=2008,m=7,d=23)
261
- # end
262
- #
263
- # end
264
-
265
- end