linked_in 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,106 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe LinkedIn::OAuth, 'when doing CRUD' do
4
+
5
+ before do
6
+ @default_options = {:access_token_path=>"/uas/oauth/accessToken", :site=>"https://api.linkedin.com",
7
+ :authorize_path=>"/uas/oauth/authorize", :request_token_path=>"/uas/oauth/requestToken?oauth_callback=oob"}
8
+ end
9
+
10
+ it "should initialize with consumer token and secret" do
11
+ linkedin = LinkedIn::OAuth.new('token', 'secret')
12
+
13
+ linkedin.ctoken.should == 'token'
14
+ linkedin.csecret.should == 'secret'
15
+ end
16
+
17
+ it "shgould set autorization path to '/uas/oauth/authorize' by default" do
18
+ linkedin = LinkedIn::OAuth.new('token', 'secret')
19
+ linkedin.consumer.options[:authorize_path].should == '/uas/oauth/authorize'
20
+ end
21
+
22
+ it "should have a consumer" do
23
+ consumer = mock('oauth consumer')
24
+ OAuth::Consumer.should_receive(:new).with('token', 'secret', @default_options).and_return(consumer)
25
+ linkedin = LinkedIn::OAuth.new('token', 'secret')
26
+ linkedin.consumer.should == consumer
27
+ end
28
+
29
+ it "should have a request token from the consumer" do
30
+ consumer = mock('oauth consumer')
31
+ request_token = mock('request token')
32
+ consumer.should_receive(:get_request_token).and_return(request_token)
33
+ OAuth::Consumer.should_receive(:new).with('token', 'secret', @default_options).and_return(consumer)
34
+ linkedin = LinkedIn::OAuth.new('token', 'secret')
35
+
36
+ linkedin.request_token.should == request_token
37
+ end
38
+
39
+ it "should clear request token and set the callback url" do
40
+ consumer = mock('oauth consumer')
41
+ request_token = mock('request token')
42
+
43
+ OAuth::Consumer.
44
+ should_receive(:new).
45
+ with('token', 'secret', @default_options).
46
+ and_return(consumer)
47
+
48
+ linkedin = LinkedIn::OAuth.new('token', 'secret')
49
+
50
+ consumer.
51
+ should_receive(:get_request_token).
52
+ with({:oauth_callback => 'http://myapp.com/oauth_callback'})
53
+
54
+ linkedin.set_callback_url('http://myapp.com/oauth_callback')
55
+ end
56
+
57
+ it "should be able to create access token from request token, request secret and verifier" do
58
+ linkedin = LinkedIn::OAuth.new('token', 'secret')
59
+ consumer = OAuth::Consumer.new('token', 'secret', @default_options)
60
+ linkedin.stub!(:consumer => consumer)
61
+
62
+ access_token = mock('access token', :token => 'atoken', :secret => 'asecret')
63
+ request_token = mock('request token')
64
+ request_token.
65
+ should_receive(:get_access_token).
66
+ with(:oauth_verifier => 'verifier').
67
+ and_return(access_token)
68
+
69
+ OAuth::RequestToken.
70
+ should_receive(:new).
71
+ with(consumer, 'rtoken', 'rsecret').
72
+ and_return(request_token)
73
+
74
+ linkedin.authorize_from_request('rtoken', 'rsecret', 'verifier')
75
+ linkedin.access_token.class.should be(OAuth::AccessToken)
76
+ linkedin.access_token.token.should == 'atoken'
77
+ linkedin.access_token.secret.should == 'asecret'
78
+ end
79
+
80
+ it "should create access token from access token and secret" do
81
+ linkedin = LinkedIn::OAuth.new('token', 'secret')
82
+ consumer = OAuth::Consumer.new('token', 'secret', @default_options)
83
+ linkedin.stub!(:consumer => consumer)
84
+
85
+ linkedin.authorize_from_access('atoken', 'asecret')
86
+ linkedin.access_token.class.should be(OAuth::AccessToken)
87
+ linkedin.access_token.token.should == 'atoken'
88
+ linkedin.access_token.secret.should == 'asecret'
89
+ end
90
+
91
+ it "should delegate get to access token" do
92
+ access_token = mock('access token')
93
+ linkedin = LinkedIn::OAuth.new('token', 'secret')
94
+ linkedin.stub!(:access_token => access_token)
95
+ access_token.should_receive(:get).and_return(nil)
96
+ linkedin.get('/foo')
97
+ end
98
+
99
+ it "should delegate post to access token" do
100
+ access_token = mock('access token')
101
+ linkedin = LinkedIn::OAuth.new('token', 'secret')
102
+ linkedin.stub!(:access_token => access_token)
103
+ access_token.should_receive(:post).and_return(nil)
104
+ linkedin.post('/foo')
105
+ end
106
+ end
@@ -0,0 +1,115 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+
3
+ describe LinkedIn::Request, 'when getting requests' do
4
+ before do
5
+ @client = mock('twitter client')
6
+ @request = LinkedIn::Request.new(@client, :get, '/statuses/user_timeline.json', {:query => {:since_id => 1234}})
7
+ end
8
+
9
+ it "should have client" do
10
+ @request.client.should == @client
11
+ end
12
+
13
+ it "should have method" do
14
+ @request.method.should == :get
15
+ end
16
+
17
+ it "should have path" do
18
+ @request.path.should == '/statuses/user_timeline.json'
19
+ end
20
+
21
+ it "should have options" do
22
+ @request.options[:query].should == {:since_id => 1234}
23
+ end
24
+
25
+ it "should have uri" do
26
+ @request.uri.should == '/statuses/user_timeline.json?since_id=1234'
27
+ end
28
+ end
29
+
30
+ describe LinkedIn::Request, 'when putting requests' do
31
+ before do
32
+ @client = mock('twitter client')
33
+ @request = LinkedIn::Request.new(@client, :put, '/statuses/user_timeline.json', {:body => '<some>xml</some>'})
34
+ end
35
+
36
+ it "should have client" do
37
+ @request.client.should == @client
38
+ end
39
+
40
+ it "should have method" do
41
+ @request.method.should == :put
42
+ end
43
+
44
+ it "should have path" do
45
+ @request.path.should == '/statuses/user_timeline.json'
46
+ end
47
+
48
+ it "should have options" do
49
+ @request.options[:body].should == '<some>xml</some>'
50
+ end
51
+ end
52
+
53
+ describe LinkedIn::Request, 'when getting raising errors' do
54
+ before do
55
+ oauth = LinkedIn::OAuth.new('token', 'secret')
56
+ oauth.authorize_from_access('atoken', 'asecret')
57
+ @client = LinkedIn::Base.new(oauth)
58
+ end
59
+
60
+ it "should not raise error for 200" do
61
+ stub_get('/foo', 'empty.xml', ['200'])
62
+ lambda {
63
+ LinkedIn::Request.get(@client, '/foo')
64
+ }.should_not raise_error
65
+ end
66
+
67
+ it "should not raise error for 304" do
68
+ stub_get('/foo', 'empty.xml', ['304'])
69
+ lambda {
70
+ LinkedIn::Request.get(@client, '/foo')
71
+ }.should_not raise_error
72
+ end
73
+
74
+ it "should raise Unauthorized for 401" do
75
+ stub_get('/foo', 'empty.xml', ['401'])
76
+ lambda {
77
+ LinkedIn::Request.get(@client, '/foo')
78
+ }.should raise_error(LinkedIn::Unauthorized)
79
+ end
80
+
81
+ it "should raise General for 403" do
82
+ stub_get('/foo', 'empty.xml', ['403'])
83
+ lambda {
84
+ LinkedIn::Request.get(@client, '/foo')
85
+ }.should raise_error(LinkedIn::Forbidden)
86
+ end
87
+
88
+ it "should raise NotFound for 404" do
89
+ stub_get('/foo', 'empty.xml', ['404'])
90
+ lambda {
91
+ LinkedIn::Request.get(@client, '/foo')
92
+ }.should raise_error(LinkedIn::NotFound)
93
+ end
94
+
95
+ it "should raise Unavailable for 500" do
96
+ stub_get('/foo', 'empty.xml', ['500'])
97
+ lambda {
98
+ LinkedIn::Request.get(@client, '/foo')
99
+ }.should raise_error(LinkedIn::Unavailable)
100
+ end
101
+
102
+ it "should raise Unavailable for 502" do
103
+ stub_get('/foo', 'empty.xml', ['502'])
104
+ lambda {
105
+ LinkedIn::Request.get(@client, '/foo')
106
+ }.should raise_error(LinkedIn::Unavailable)
107
+ end
108
+
109
+ it "should raise Unavailable for 503" do
110
+ stub_get('/foo', 'empty.xml', ['503'])
111
+ lambda {
112
+ LinkedIn::Request.get(@client, '/foo')
113
+ }.should raise_error(LinkedIn::Unavailable)
114
+ end
115
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,39 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+
11
+ require 'linked_in'
12
+ require 'fakeweb'
13
+
14
+ FakeWeb.allow_net_connect = false
15
+
16
+ def linkedin_url(path)
17
+ "https://api.linkedin.com#{path}"
18
+ end
19
+
20
+ def fixture_file(filename)
21
+ return '' if filename == ''
22
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
23
+ File.read(file_path)
24
+ end
25
+
26
+ def stub_get(url, filename, status=nil)
27
+ options = {:body => fixture_file(filename)}
28
+ options.merge!({:status => status}) unless status.nil?
29
+
30
+ FakeWeb.register_uri(:get, linkedin_url(url), options)
31
+ end
32
+
33
+ def stub_post(url, filename)
34
+ FakeWeb.register_uri(:post, linkedin_url(url), :body => fixture_file(filename))
35
+ end
36
+
37
+ def stub_put(url, filename)
38
+ FakeWeb.register_uri(:put, linkedin_url(url), :body => fixture_file(filename))
39
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linked_in
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.21
5
+ platform: ruby
6
+ authors:
7
+ - Peter T. Brown
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-25 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: oauth
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.5
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: jordi-xml-object
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.91
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: hoe
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.3.3
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: oauth
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 0.3.5
64
+ version:
65
+ - !ruby/object:Gem::Dependency
66
+ name: jordi-xml-object
67
+ type: :development
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 0.9.91
74
+ version:
75
+ description: The linked_in gem wraps the LinkedIn API, including support for OAuth
76
+ email:
77
+ - peter@flippyhead.com
78
+ executables: []
79
+
80
+ extensions: []
81
+
82
+ extra_rdoc_files:
83
+ - History.txt
84
+ - Manifest.txt
85
+ - PostInstall.txt
86
+ - README.rdoc
87
+ files:
88
+ - History.txt
89
+ - Manifest.txt
90
+ - PostInstall.txt
91
+ - README.rdoc
92
+ - Rakefile
93
+ - docs/sample-oauth-plugin_token.rb
94
+ - lib/linked_in.rb
95
+ - lib/linked_in/base.rb
96
+ - lib/linked_in/oauth.rb
97
+ - lib/linked_in/request.rb
98
+ - linked_in.gemspec
99
+ - script/console
100
+ - script/destroy
101
+ - script/generate
102
+ - spec/fixtures/connections.xml
103
+ - spec/fixtures/connections_with_field_selectors.xml
104
+ - spec/fixtures/empty.xml
105
+ - spec/fixtures/error.xml
106
+ - spec/fixtures/network.xml
107
+ - spec/fixtures/people.xml
108
+ - spec/fixtures/profile.xml
109
+ - spec/linked_in/base_spec.rb
110
+ - spec/linked_in/oauth_spec.rb
111
+ - spec/linked_in/request_spec.rb
112
+ - spec/spec.opts
113
+ - spec/spec_helper.rb
114
+ - tasks/rspec.rake
115
+ has_rdoc: true
116
+ homepage: http://github.com/flippyhead/linked_in
117
+ licenses: []
118
+
119
+ post_install_message: PostInstall.txt
120
+ rdoc_options:
121
+ - --main
122
+ - README.rdoc
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: "0"
130
+ version:
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: "0"
136
+ version:
137
+ requirements: []
138
+
139
+ rubyforge_project:
140
+ rubygems_version: 1.3.5
141
+ signing_key:
142
+ specification_version: 3
143
+ summary: The linked_in gem wraps the LinkedIn API making it easy to read and write profile information and messages on http://linked_in.com. Full support for OAuth is provided including a wrapper for Pelle's oauth-plugin (http://github.com/pelle/oauth-plugin/). This gem borrowed heavily from junemakers twitter gem (http://github.com/jnunemaker/twitter/).
144
+ test_files: []
145
+