linkedin-rb 0.0.1

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.
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
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.
@@ -0,0 +1,3 @@
1
+ = linkedin-rb
2
+
3
+ Documentation coming soon.
@@ -0,0 +1,3 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new('spec')
@@ -0,0 +1,11 @@
1
+ require 'oauth'
2
+ require 'active_support/all'
3
+
4
+ require 'linked_in/extensions/string'
5
+ require 'linked_in/configuration'
6
+ require 'linked_in/client'
7
+ require 'linked_in/version'
8
+
9
+ module LinkedIn
10
+ extend Configuration
11
+ end
@@ -0,0 +1,52 @@
1
+ require 'linked_in/api/person'
2
+ require 'linked_in/api/group'
3
+ require 'linked_in/api/post'
4
+ require 'linked_in/api/comment'
5
+ require 'linked_in/api/company'
6
+
7
+ module LinkedIn
8
+ module API
9
+ include LinkedIn::API::Person
10
+ include LinkedIn::API::Group
11
+ include LinkedIn::API::Post
12
+ include LinkedIn::API::Comment
13
+ include LinkedIn::API::Company
14
+
15
+ def get(path, options={})
16
+ options = { :format => 'json', :fields => nil }.merge(options)
17
+ fields = options.delete(:fields)
18
+ request(:get, "#{base_uri}/#{build_request(path, fields, options)}")
19
+ end
20
+
21
+ def get_object(object, id_or_param, options={})
22
+ query = parse_query(id_or_param)
23
+ get("#{object}/#{query}", options)
24
+ end
25
+
26
+ def get_objects(object, ids, options={})
27
+ get("#{object}::(#{ids.join(',')})", options)
28
+ end
29
+
30
+ def get_collection(object, id_or_param, collection, options={})
31
+ query = parse_query(id_or_param)
32
+ get("#{object}/#{query}/#{collection}", options)
33
+ end
34
+
35
+ private
36
+ def parse_query(id_or_param)
37
+ id_or_param.is_a?(Hash) ? id_or_param.to_param : id_or_param
38
+ end
39
+
40
+ def fields_from_options(options)
41
+ options.delete(:fields) || nil
42
+ end
43
+
44
+ def build_request(path, fields, options)
45
+ request = ""
46
+ request << "#{path}"
47
+ request << ":(#{fields.join(',')})" unless fields.blank?
48
+ request << "?#{options.to_param}" unless options.blank?
49
+ request
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,14 @@
1
+ module LinkedIn
2
+ module API
3
+ module Comment
4
+ def get_comment(id_or_params, options={})
5
+ get_object("comments", id_or_params, options)
6
+ end
7
+
8
+ # Batch lookups
9
+ def get_comments(ids, options={})
10
+ get_objects("comments", ids, options)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ module LinkedIn
2
+ module API
3
+ module Company
4
+ def search_companies(keywords, options={})
5
+ options = { :keywords => keywords }.merge(options)
6
+ get("company-search", options)
7
+ end
8
+
9
+ def get_company(id_or_params, options={})
10
+ get_object("companies", id_or_params, options)
11
+ end
12
+
13
+ def get_company_products(id_or_params, options={})
14
+ get_collection("companies", id_or_params, "products", options)
15
+ end
16
+
17
+ # Batch lookups
18
+ def get_companies(ids, options={})
19
+ get_objects("companies", ids, options)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ module LinkedIn
2
+ module API
3
+ module Group
4
+ def get_group(id_or_params, options={})
5
+ get_object("groups", id_or_params, options)
6
+ end
7
+
8
+ def get_group_posts(id_or_params, options={})
9
+ get_collection("groups", id_or_params, "posts", options)
10
+ end
11
+
12
+ # Batch lookups
13
+ def get_groups(ids, options={})
14
+ get_objects("groups", ids, options)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,61 @@
1
+ module LinkedIn
2
+ module API
3
+ module Person
4
+
5
+ # Self methods
6
+ def get_me(options={})
7
+ get_person("~", options)
8
+ end
9
+
10
+ def get_my_connections(options={})
11
+ get_person_connections("~", options)
12
+ end
13
+
14
+ def get_my_memberships(options={})
15
+ get_person_memberships("~", options)
16
+ end
17
+
18
+ def get_my_suggestions(options={})
19
+ get_person_suggestions("~", options)
20
+ end
21
+
22
+ def get_my_followed_companies(options={})
23
+ get_person_followed_companies("~", options)
24
+ end
25
+
26
+ def get_my_suggested_companies(options={})
27
+ get_person_suggested_companies("~", options)
28
+ end
29
+
30
+ # Person methods
31
+ def get_person(id_or_params, options={})
32
+ get_object("people", id_or_params, options)
33
+ end
34
+
35
+ def get_person_connections(id_or_params, options={})
36
+ get_collection("people", id_or_params, "connections", options)
37
+ end
38
+
39
+ def get_person_memberships(id_or_params, options={})
40
+ get_collection("people", id_or_params, "group-memberships", options)
41
+ end
42
+
43
+ def get_person_suggestions(id_or_params, options={})
44
+ get_collection("people", id_or_params, "suggestions/groups", options)
45
+ end
46
+
47
+ def get_person_followed_companies(id_or_params, options={})
48
+ get_collection("people", id_or_params, "following/companies", options)
49
+ end
50
+
51
+ def get_person_suggested_companies(id_or_params, options={})
52
+ get_collection("people", id_or_params, "suggestions/to-follow/companies", options)
53
+ end
54
+
55
+ # Batch lookups
56
+ def get_people(ids, options={})
57
+ get_objects("people", ids, options)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,14 @@
1
+ module LinkedIn
2
+ module API
3
+ module Post
4
+ def get_post(id_or_params, options={})
5
+ get_object("posts", id_or_params, options)
6
+ end
7
+
8
+ # Batch lookups
9
+ def get_posts(ids, options={})
10
+ get_objects("posts", ids, options)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,42 @@
1
+ require 'linked_in/request'
2
+ require 'linked_in/api'
3
+
4
+ module LinkedIn
5
+ class Client
6
+ include LinkedIn::Request
7
+ include LinkedIn::API
8
+
9
+ attr_accessor :oauth_token, :oauth_secret
10
+
11
+ def initialize(oauth_token, oauth_secret)
12
+ @oauth_token = oauth_token
13
+ @oauth_secret = oauth_secret
14
+
15
+ raise StandardError, "Configuration: consumer_key is required" if consumer_key.blank?
16
+ raise StandardError, "Configuration: consumer_secret is required" if consumer_secret.blank?
17
+ raise StandardError, "Configuration: base_uri is required" if base_uri.blank?
18
+ end
19
+
20
+ def consumer
21
+ ::OAuth::Consumer.new(consumer_key, consumer_secret)
22
+ end
23
+
24
+ def access_token
25
+ ::OAuth::AccessToken.new(consumer, oauth_token, oauth_secret)
26
+ end
27
+
28
+ private
29
+
30
+ def consumer_key
31
+ @consumer_key ||= LinkedIn.consumer_key
32
+ end
33
+
34
+ def consumer_secret
35
+ @consumer_secret ||= LinkedIn.consumer_secret
36
+ end
37
+
38
+ def base_uri
39
+ @base_uri ||= LinkedIn.base_uri
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ module LinkedIn
2
+ module Configuration
3
+ DEFAULT_OPTIONS = {
4
+ :base_uri => 'http://api.linkedin.com/v1',
5
+ :consumer_key => nil,
6
+ :consumer_secret => nil }
7
+
8
+ attr_accessor *DEFAULT_OPTIONS.keys
9
+
10
+ def self.extended(base)
11
+ base.reset
12
+ end
13
+
14
+ def configure
15
+ yield self
16
+ self
17
+ end
18
+
19
+ def reset
20
+ self.configure do |config|
21
+ DEFAULT_OPTIONS.each_pair do |key, value|
22
+ self.send("#{key}=", value)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ require 'json'
2
+
3
+ class String
4
+ def from_json
5
+ JSON.parse(self)
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'linked_in/response'
2
+
3
+ module LinkedIn
4
+ module Request
5
+ def request(method, uri)
6
+ LinkedIn::Response.new(access_token.send(method, uri))
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module LinkedIn
2
+ class Response
3
+ attr_accessor :code, :body
4
+
5
+ def initialize(response)
6
+ @code = response.code
7
+ @body = response.body.from_json
8
+ end
9
+
10
+ def [](attribute)
11
+ body[attribute]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module LinkedIn
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :linked_in do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+ require 'linked_in'
3
+
4
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f }
5
+
6
+ RSpec.configure do |config|
7
+ config.color_enabled = true
8
+ config.formatter = 'documentation'
9
+ end
@@ -0,0 +1,7 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
5
+ c.hook_into :webmock
6
+ c.default_cassette_options = { :record => :new_episodes }
7
+ end
@@ -0,0 +1,32 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe LinkedIn::API::Comment do
4
+ before do
5
+ LinkedIn.configure do |config|
6
+ config.consumer_key = "consumer-key"
7
+ config.consumer_secret = "consumer-secret"
8
+ end
9
+ end
10
+
11
+ describe "with an initialized client" do
12
+ before do
13
+ @client = LinkedIn::Client.new("oauth-token", "oauth-secret")
14
+ @response = double('response', :body => {}, :code => 200)
15
+ @client.stub(:get).and_return(@response)
16
+ end
17
+
18
+ describe "#get_comment" do
19
+ it "should make a GET request on /comments/[params]" do
20
+ @client.should_receive(:get).with("comments/~", {})
21
+ @client.get_comment("~")
22
+ end
23
+ end
24
+
25
+ describe "#get_comments" do
26
+ it "should make a GET request on /comments::[ids]" do
27
+ @client.should_receive(:get).with("comments::(1,2,3)", {})
28
+ @client.get_comments(['1', '2', '3'])
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,39 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe LinkedIn::API::Company do
4
+ before do
5
+ LinkedIn.configure do |config|
6
+ config.consumer_key = "consumer-key"
7
+ config.consumer_secret = "consumer-secret"
8
+ end
9
+ end
10
+
11
+ describe "with an initialized client" do
12
+ before do
13
+ @client = LinkedIn::Client.new("oauth-token", "oauth-secret")
14
+ @response = double('response', :body => {}, :code => 200)
15
+ @client.stub(:get).and_return(@response)
16
+ end
17
+
18
+ describe "#search_companies" do
19
+ it "should make a GET request on /company-search?keywords=[keywords]" do
20
+ @client.should_receive(:get).with("company-search", { :keywords => 'keyword' })
21
+ @client.search_companies('keyword')
22
+ end
23
+ end
24
+
25
+ describe "#get_company" do
26
+ it "should make a GET request on /companies/[params]" do
27
+ @client.should_receive(:get).with("companies/~", {})
28
+ @client.get_company("~")
29
+ end
30
+ end
31
+
32
+ describe "#get_companies" do
33
+ it "should make a GET request on /companies::[ids]" do
34
+ @client.should_receive(:get).with("companies::(1,2,3)", {})
35
+ @client.get_companies(['1', '2', '3'])
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe LinkedIn::API::Group do
4
+ before do
5
+ LinkedIn.configure do |config|
6
+ config.consumer_key = "consumer-key"
7
+ config.consumer_secret = "consumer-secret"
8
+ end
9
+ end
10
+
11
+ describe "with an initialized client" do
12
+ before do
13
+ @client = LinkedIn::Client.new("oauth-token", "oauth-secret")
14
+ @response = double('response', :body => {}, :code => 200)
15
+ @client.stub(:get).and_return(@response)
16
+ end
17
+
18
+ describe "#get_group" do
19
+ it "should make a GET request on /groups/[params]" do
20
+ @client.should_receive(:get).with("groups/~", {})
21
+ @client.get_group("~")
22
+ end
23
+ end
24
+
25
+ describe "#get_group_posts" do
26
+ it "should make a GET request on /groups/[params]/posts" do
27
+ @client.should_receive(:get).with("groups/~/posts", {})
28
+ @client.get_group_posts("~")
29
+ end
30
+ end
31
+
32
+ describe "#get_groups" do
33
+ it "should make a GET request on /groups::[ids]" do
34
+ @client.should_receive(:get).with("groups::(1,2,3)", {})
35
+ @client.get_groups(['1', '2', '3'])
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,109 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe LinkedIn::API::Person do
4
+ before do
5
+ LinkedIn.configure do |config|
6
+ config.consumer_key = "consumer-key"
7
+ config.consumer_secret = "consumer-secret"
8
+ end
9
+ end
10
+
11
+ describe "with an initialized client" do
12
+ before do
13
+ @client = LinkedIn::Client.new("oauth-token", "oauth-secret")
14
+ @response = double('response', :body => {}, :code => 200)
15
+ @client.stub(:get).and_return(@response)
16
+ end
17
+
18
+ describe "#get_me" do
19
+ it "should request the currently authenticated person" do
20
+ @client.should_receive(:get_person).with("~", {})
21
+ @client.get_me
22
+ end
23
+ end
24
+
25
+ describe "#get_my_connections" do
26
+ it "should request the currently authenticated person's connections" do
27
+ @client.should_receive(:get_person_connections).with("~", {})
28
+ @client.get_my_connections
29
+ end
30
+ end
31
+
32
+ describe "#get_my_memberships" do
33
+ it "should request the currently authenticated person's memberships" do
34
+ @client.should_receive(:get_person_memberships).with("~", {})
35
+ @client.get_my_memberships
36
+ end
37
+ end
38
+
39
+ describe "#get_my_suggestions" do
40
+ it "should request the currently authenticated person's suggestions" do
41
+ @client.should_receive(:get_person_suggestions).with("~", {})
42
+ @client.get_my_suggestions
43
+ end
44
+ end
45
+
46
+ describe "#get_my_followed_companies" do
47
+ it "should request the currently authenticated person's followed companies" do
48
+ @client.should_receive(:get_person_followed_companies).with("~", {})
49
+ @client.get_my_followed_companies
50
+ end
51
+ end
52
+
53
+ describe "#get_my_suggested_companies" do
54
+ it "should request the currently authenticated person's suggested companies" do
55
+ @client.should_receive(:get_person_suggested_companies).with("~", {})
56
+ @client.get_my_suggested_companies
57
+ end
58
+ end
59
+
60
+ describe "#get_person" do
61
+ it "should make a GET request on /people/[params]" do
62
+ @client.should_receive(:get).with("people/~", {})
63
+ @client.get_person('~')
64
+ end
65
+ end
66
+
67
+ describe "#get_person_connections" do
68
+ it "should make a GET request on /people/[params]/connections" do
69
+ @client.should_receive(:get).with("people/~/connections", {})
70
+ @client.get_person_connections("~")
71
+ end
72
+ end
73
+
74
+ describe "#get_person_memberships" do
75
+ it "should make a GET request on /people/[params]/group-memberships" do
76
+ @client.should_receive(:get).with("people/~/group-memberships", {})
77
+ @client.get_person_memberships("~")
78
+ end
79
+ end
80
+
81
+ describe "#get_person_suggestions" do
82
+ it "should make a GET request on /people/[params]/suggestions/groups" do
83
+ @client.should_receive(:get).with("people/~/suggestions/groups", {})
84
+ @client.get_person_suggestions("~")
85
+ end
86
+ end
87
+
88
+ describe "#get_person_followed_companies" do
89
+ it "should make a GET request on /people/[params]/following/companies" do
90
+ @client.should_receive(:get).with("people/~/following/companies", {})
91
+ @client.get_person_followed_companies("~")
92
+ end
93
+ end
94
+
95
+ describe "#get_person_suggested_companies" do
96
+ it "should make a GET request on /people/[params]/suggestions/to-follow/companies" do
97
+ @client.should_receive(:get).with("people/~/suggestions/to-follow/companies", {})
98
+ @client.get_person_suggested_companies("~")
99
+ end
100
+ end
101
+
102
+ describe "#get_people" do
103
+ it "should make a GET request on /people::[ids]" do
104
+ @client.should_receive(:get).with("people::(1,2,3)", {})
105
+ @client.get_people(['1', '2', '3'])
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,32 @@
1
+ require_relative '../../../spec_helper'
2
+
3
+ describe LinkedIn::API::Post do
4
+ before do
5
+ LinkedIn.configure do |config|
6
+ config.consumer_key = "consumer-key"
7
+ config.consumer_secret = "consumer-secret"
8
+ end
9
+ end
10
+
11
+ describe "with an initialized client" do
12
+ before do
13
+ @client = LinkedIn::Client.new("oauth-token", "oauth-secret")
14
+ @response = double('response', :body => {}, :code => 200)
15
+ @client.stub(:get).and_return(@response)
16
+ end
17
+
18
+ describe "#get_post" do
19
+ it "should make a GET request on /posts/[params]" do
20
+ @client.should_receive(:get).with("posts/~", {})
21
+ @client.get_post("~")
22
+ end
23
+ end
24
+
25
+ describe "#get_posts" do
26
+ it "should make a GET request on /posts::[ids]" do
27
+ @client.should_receive(:get).with("posts::(1,2,3)", {})
28
+ @client.get_posts(['1', '2', '3'])
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,77 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe LinkedIn::API do
4
+ before do
5
+ LinkedIn.configure do |config|
6
+ config.consumer_key = "consumer-key"
7
+ config.consumer_secret = "consumer-secret"
8
+ end
9
+ end
10
+
11
+ describe "with an initialized client" do
12
+ before do
13
+ @client = LinkedIn::Client.new("oauth-token", "oauth-secret")
14
+ @response = double('response', :body => {}, :code => 200)
15
+ end
16
+
17
+ describe "#get" do
18
+ it "should make a GET request to the path with the specified options" do
19
+ @client.should_receive(:request).with(:get, "http://api.linkedin.com/v1/people/~?format=json&option=value")
20
+ @client.get('people/~', { :option => 'value' })
21
+ end
22
+ end
23
+
24
+ describe "#get_object" do
25
+ context "by path" do
26
+ it "should make a GET request to the endpoint with a path string" do
27
+ @client.should_receive(:get).with("people/~", {}).and_return(@response)
28
+ @client.get_object('people', '~')
29
+ end
30
+ end
31
+
32
+ context "by ID" do
33
+ it "should make a GET request to the endpoint with an ID parameter" do
34
+ @client.should_receive(:get).with("people/id=1234", {}).and_return(@response)
35
+ @client.get_object('people', { :id => '1234' })
36
+ end
37
+ end
38
+
39
+ context "by URL" do
40
+ it "should make a GET request to the endpoint with a URL parameter" do
41
+ @client.should_receive(:get).with("people/url=http%3A%2F%2Fgoogle.com", {}).and_return(@response)
42
+ @client.get_object('people', { :url => 'http://google.com' })
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "#get_objects" do
48
+ it "should make a GET request to the endpoint with multiple IDs" do
49
+ @client.should_receive(:get).with("people::(1,2,3)", {}).and_return(@response)
50
+ @client.get_objects('people', ['1', '2', '3'])
51
+ end
52
+ end
53
+
54
+ describe "#get_collection" do
55
+ context "by path" do
56
+ it "should make a GET request to the endpoint with a path string" do
57
+ @client.should_receive(:get).with("people/~/connections", {}).and_return(@response)
58
+ @client.get_collection('people', '~', 'connections')
59
+ end
60
+ end
61
+
62
+ context "by ID" do
63
+ it "should make a GET request to the endpoint with an ID parameter" do
64
+ @client.should_receive(:get).with("people/id=1234/connections", {}).and_return(@response)
65
+ @client.get_collection('people', { :id => 1234 }, 'connections')
66
+ end
67
+ end
68
+
69
+ context "by URL" do
70
+ it "should make a GET request to the endpoint with a URL parameter" do
71
+ @client.should_receive(:get).with("people/url=http%3A%2F%2Fgoogle.com/connections", {}).and_return(@response)
72
+ @client.get_collection('people', { :url => 'http://google.com' }, 'connections')
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,60 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe LinkedIn::Client do
4
+ context "with configuration" do
5
+ before do
6
+ LinkedIn.configure do |config|
7
+ config.consumer_key = "consumer-key"
8
+ config.consumer_secret = "consumer-secret"
9
+ end
10
+ end
11
+
12
+ context "an initialized client" do
13
+ before do
14
+ @client = LinkedIn::Client.new("oauth-token", "oauth-secret")
15
+ end
16
+
17
+ it "sets the oauth token" do
18
+ @client.oauth_token.should == "oauth-token"
19
+ end
20
+
21
+ it "sets the oauth secret" do
22
+ @client.oauth_secret.should == "oauth-secret"
23
+ end
24
+
25
+ describe "#consumer" do
26
+ it "should initialize an oauth consumer" do
27
+ OAuth::Consumer.should_receive(:new).with("consumer-key", "consumer-secret")
28
+ @client.consumer
29
+ end
30
+ end
31
+
32
+ describe "#access_token" do
33
+ before do
34
+ @consumer = double('consumer')
35
+ @client.stub(:consumer) { @consumer }
36
+ end
37
+
38
+ it "should initialize an oauth access token" do
39
+ OAuth::AccessToken.should_receive(:new).with(@consumer, "oauth-token", "oauth-secret")
40
+ @client.access_token
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ context "without configuration" do
47
+ before do
48
+ LinkedIn.configure do |config|
49
+ config.consumer_key = nil
50
+ config.consumer_secret = nil
51
+ end
52
+ end
53
+
54
+ it "should raise an error" do
55
+ expect do
56
+ @client = LinkedIn::Client.new("oauth-token", "oauth-secret")
57
+ end.to raise_error
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,37 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe LinkedIn::Request do
4
+ before do
5
+ LinkedIn.configure do |config|
6
+ config.consumer_key = "consumer-key"
7
+ config.consumer_secret = "consumer-secret"
8
+ end
9
+ end
10
+
11
+ describe "with an initialized client" do
12
+ before do
13
+ @client = LinkedIn::Client.new("oauth-token", "oauth-secret")
14
+ @access_token = mock('access token')
15
+ @client.stub(:access_token) { @access_token }
16
+ end
17
+
18
+ describe "#request" do
19
+ before do
20
+ @response = mock('response')
21
+ @response.stub(:code)
22
+ @response.stub(:body) { { 'test' => 'value' }.to_json }
23
+ @access_token.stub(:get) { @response }
24
+ end
25
+
26
+ it "should make a GET request on the access token" do
27
+ @access_token.should_receive(:get).with("test/path")
28
+ @client.request(:get, "test/path")
29
+ end
30
+
31
+ it "should initialize a new response" do
32
+ LinkedIn::Response.should_receive(:new).with(@response)
33
+ @client.request(:get, "test/path")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ require 'json'
2
+ require_relative '../../spec_helper'
3
+
4
+ describe LinkedIn::Response do
5
+ describe "an initialized request" do
6
+ before do
7
+ @code = 200
8
+ @body = {"keyOne" => "value"}.to_json
9
+ raw_response = mock('raw response')
10
+ raw_response.stub(:code) { @code }
11
+ raw_response.stub(:body) { @body }
12
+ @response = LinkedIn::Response.new(raw_response)
13
+ end
14
+
15
+ it "should set the code" do
16
+ @response.code.should == @code
17
+ end
18
+
19
+ it "should set the body" do
20
+ @response.body.should == @body.from_json
21
+ end
22
+
23
+ context "#[]" do
24
+ it "should return the value for a key in #parsed_body" do
25
+ @response['keyOne'].should == 'value'
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe LinkedIn do
4
+ it "has a version" do
5
+ LinkedIn.const_defined?("VERSION").should be_true
6
+ end
7
+
8
+ describe ".configure" do
9
+ LinkedIn::Configuration::DEFAULT_OPTIONS.each_key do |key|
10
+ it "should set the #{key}" do
11
+ LinkedIn.configure do |config|
12
+ config.send("#{key}=", key)
13
+ end
14
+ LinkedIn.send(key).should == key
15
+ end
16
+ end
17
+ end
18
+
19
+ describe ".reset" do
20
+ LinkedIn::Configuration::DEFAULT_OPTIONS.each_pair do |key, value|
21
+ it "should set the default #{key}" do
22
+ LinkedIn.configure do |config|
23
+ config.send("#{key}=", value)
24
+ end
25
+ LinkedIn.send(key).should == value
26
+ end
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linkedin-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Hite
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-31 00:00:00.000000000 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: oauth
17
+ requirement: &70112080037320 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 0.4.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70112080037320
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ requirement: &70112080036820 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70112080036820
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &70112080036360 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.0.15
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70112080036360
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: &70112080035900 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '2.6'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *70112080035900
59
+ - !ruby/object:Gem::Dependency
60
+ name: webmock
61
+ requirement: &70112080035440 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 1.7.7
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *70112080035440
70
+ - !ruby/object:Gem::Dependency
71
+ name: vcr
72
+ requirement: &70112080034980 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.0.0.beta1
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *70112080034980
81
+ - !ruby/object:Gem::Dependency
82
+ name: ruby-debug19
83
+ requirement: &70112080034600 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *70112080034600
92
+ description: A wrapper for the LinkedIn API
93
+ email:
94
+ - andrew@andrew-hite.com
95
+ executables: []
96
+ extensions: []
97
+ extra_rdoc_files: []
98
+ files:
99
+ - lib/linked_in/api/comment.rb
100
+ - lib/linked_in/api/company.rb
101
+ - lib/linked_in/api/group.rb
102
+ - lib/linked_in/api/person.rb
103
+ - lib/linked_in/api/post.rb
104
+ - lib/linked_in/api.rb
105
+ - lib/linked_in/client.rb
106
+ - lib/linked_in/configuration.rb
107
+ - lib/linked_in/extensions/string.rb
108
+ - lib/linked_in/request.rb
109
+ - lib/linked_in/response.rb
110
+ - lib/linked_in/version.rb
111
+ - lib/linked_in.rb
112
+ - lib/tasks/linked_in_tasks.rake
113
+ - MIT-LICENSE
114
+ - Rakefile
115
+ - README.rdoc
116
+ - spec/spec_helper.rb
117
+ - spec/support/vcr.rb
118
+ - spec/units/linked_in/api/comment_spec.rb
119
+ - spec/units/linked_in/api/company_spec.rb
120
+ - spec/units/linked_in/api/group_spec.rb
121
+ - spec/units/linked_in/api/person_spec.rb
122
+ - spec/units/linked_in/api/post_spec.rb
123
+ - spec/units/linked_in/api_spec.rb
124
+ - spec/units/linked_in/client_spec.rb
125
+ - spec/units/linked_in/request_spec.rb
126
+ - spec/units/linked_in/response_spec.rb
127
+ - spec/units/linked_in_spec.rb
128
+ has_rdoc: true
129
+ homepage: http://andrew-hite.com
130
+ licenses: []
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 1.6.2
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: A wrapper for the LinkedIn API
153
+ test_files:
154
+ - spec/spec_helper.rb
155
+ - spec/support/vcr.rb
156
+ - spec/units/linked_in/api/comment_spec.rb
157
+ - spec/units/linked_in/api/company_spec.rb
158
+ - spec/units/linked_in/api/group_spec.rb
159
+ - spec/units/linked_in/api/person_spec.rb
160
+ - spec/units/linked_in/api/post_spec.rb
161
+ - spec/units/linked_in/api_spec.rb
162
+ - spec/units/linked_in/client_spec.rb
163
+ - spec/units/linked_in/request_spec.rb
164
+ - spec/units/linked_in/response_spec.rb
165
+ - spec/units/linked_in_spec.rb