linkedin-api2 1.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +14 -0
  3. data/.gemtest +0 -0
  4. data/.gitignore +42 -0
  5. data/.rspec +1 -0
  6. data/.travis.yml +6 -0
  7. data/.yardopts +7 -0
  8. data/CHANGELOG.md +99 -0
  9. data/EXAMPLES.md +202 -0
  10. data/Gemfile +11 -0
  11. data/LICENSE +22 -0
  12. data/README.md +43 -0
  13. data/Rakefile +15 -0
  14. data/lib/linked_in/api.rb +38 -0
  15. data/lib/linked_in/api/communications.rb +44 -0
  16. data/lib/linked_in/api/companies.rb +129 -0
  17. data/lib/linked_in/api/groups.rb +115 -0
  18. data/lib/linked_in/api/jobs.rb +64 -0
  19. data/lib/linked_in/api/people.rb +73 -0
  20. data/lib/linked_in/api/query_helpers.rb +86 -0
  21. data/lib/linked_in/api/share_and_social_stream.rb +137 -0
  22. data/lib/linked_in/client.rb +51 -0
  23. data/lib/linked_in/errors.rb +29 -0
  24. data/lib/linked_in/helpers.rb +6 -0
  25. data/lib/linked_in/helpers/authorization.rb +69 -0
  26. data/lib/linked_in/helpers/request.rb +85 -0
  27. data/lib/linked_in/mash.rb +95 -0
  28. data/lib/linked_in/search.rb +71 -0
  29. data/lib/linked_in/version.rb +11 -0
  30. data/lib/linkedin.rb +35 -0
  31. data/linkedin-api2.gemspec +27 -0
  32. data/spec/cases/api_spec.rb +308 -0
  33. data/spec/cases/linkedin_spec.rb +37 -0
  34. data/spec/cases/mash_spec.rb +113 -0
  35. data/spec/cases/oauth_spec.rb +178 -0
  36. data/spec/cases/search_spec.rb +234 -0
  37. data/spec/fixtures/cassette_library/LinkedIn_Api/Company_API.yml +81 -0
  38. data/spec/fixtures/cassette_library/LinkedIn_Api/Company_API/should_load_correct_company_data.yml +81 -0
  39. data/spec/fixtures/cassette_library/LinkedIn_Client/_authorize_from_request/should_return_a_valid_access_token.yml +37 -0
  40. data/spec/fixtures/cassette_library/LinkedIn_Client/_request_token/with_a_callback_url/should_return_a_valid_access_token.yml +37 -0
  41. data/spec/fixtures/cassette_library/LinkedIn_Client/_request_token/with_default_options/should_return_a_valid_request_token.yml +37 -0
  42. data/spec/fixtures/cassette_library/LinkedIn_Search/_search/by_company_name_option/should_perform_a_search.yml +92 -0
  43. data/spec/fixtures/cassette_library/LinkedIn_Search/_search/by_email_address/should_perform_a_people_search.yml +57 -0
  44. data/spec/fixtures/cassette_library/LinkedIn_Search/_search/by_first_name_and_last_name_options/should_perform_a_search.yml +100 -0
  45. data/spec/fixtures/cassette_library/LinkedIn_Search/_search/by_first_name_and_last_name_options_with_fields/should_perform_a_search.yml +114 -0
  46. data/spec/fixtures/cassette_library/LinkedIn_Search/_search/by_keywords_string_parameter/should_perform_a_search.yml +52 -0
  47. data/spec/fixtures/cassette_library/LinkedIn_Search/_search/by_multiple_email_address/should_perform_a_multi-email_search.yml +59 -0
  48. data/spec/fixtures/cassette_library/LinkedIn_Search/_search/by_single_keywords_option/should_perform_a_search.yml +52 -0
  49. data/spec/fixtures/cassette_library/LinkedIn_Search/_search/by_single_keywords_option_with_pagination/should_perform_a_search.yml +43 -0
  50. data/spec/fixtures/cassette_library/LinkedIn_Search/_search/email_search_returns_unauthorized/should_raise_an_unauthorized_error.yml +59 -0
  51. data/spec/fixtures/cassette_library/LinkedIn_Search/_search_company/by_keywords_options_with_fields/should_perform_a_search.yml +43 -0
  52. data/spec/fixtures/cassette_library/LinkedIn_Search/_search_company/by_keywords_string_parameter/should_perform_a_company_search.yml +80 -0
  53. data/spec/fixtures/cassette_library/LinkedIn_Search/_search_company/by_single_keywords_option/should_perform_a_company_search.yml +80 -0
  54. data/spec/fixtures/cassette_library/LinkedIn_Search/_search_company/by_single_keywords_option_with_facets_to_return/should_return_a_facet.yml +80 -0
  55. data/spec/fixtures/cassette_library/LinkedIn_Search/_search_company/by_single_keywords_option_with_pagination/should_perform_a_search.yml +74 -0
  56. data/spec/helper.rb +34 -0
  57. metadata +268 -0
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :test => :spec
10
+ task :default => :spec
11
+ load 'vcr/tasks/vcr.rake'
12
+
13
+ require File.expand_path('../lib/linked_in/version', __FILE__)
14
+ require 'yard'
15
+ YARD::Rake::YardocTask.new
@@ -0,0 +1,38 @@
1
+ module LinkedIn
2
+ module Api
3
+
4
+ # @!macro person_path_options
5
+ # @param [Hash] options identifies the user profile you want
6
+ # @option options [String] :id a member token
7
+ # @option options [String] :url a Public Profile URL
8
+ # @option options [String] :email
9
+
10
+ # @!macro company_path_options
11
+ # @param [Hash] options identifies the user profile you want
12
+ # @option options [String] :domain company email domain
13
+ # @option options [String] :id company ID
14
+ # @option options [String] :url
15
+ # @option options [String] :name company universal name
16
+ # @option options [String] :is_admin list all companies that the
17
+ # authenticated is an administrator of
18
+
19
+ # @!macro share_input_fields
20
+ # @param [Hash] share content of the share
21
+ # @option share [String] :comment
22
+ # @option share [String] :content
23
+ # @option share [String] :title
24
+ # @option share [String] :submitted-url
25
+ # @option share [String] :submitted-image-url
26
+ # @option share [String] :description
27
+ # @option share [String] :visibility
28
+ # @option share [String] :code
29
+
30
+ autoload :QueryHelpers, "linked_in/api/query_helpers"
31
+ autoload :People, "linked_in/api/people"
32
+ autoload :Groups, "linked_in/api/groups"
33
+ autoload :Companies, "linked_in/api/companies"
34
+ autoload :Jobs, "linked_in/api/jobs"
35
+ autoload :ShareAndSocialStream, "linked_in/api/share_and_social_stream"
36
+ autoload :Communications, "linked_in/api/communications"
37
+ end
38
+ end
@@ -0,0 +1,44 @@
1
+ module LinkedIn
2
+ module Api
3
+
4
+ # Communications APIs
5
+ #
6
+ # @see http://developer.linkedin.com/documents/communications
7
+ module Communications
8
+
9
+ # (Create) send a message from the authenticated user to a
10
+ # connection
11
+ #
12
+ # Permissions: w_messages
13
+ #
14
+ # @see http://developer.linkedin.com/documents/messaging-between-connections-api
15
+ # @see http://developer.linkedin.com/documents/invitation-api Invitation API
16
+ #
17
+ # @example
18
+ # client.send_message("subject", "body", ["person_1_id", "person_2_id"])
19
+ #
20
+ # @param [String] subject Subject of the message
21
+ # @param [String] body Body of the message, plain text only
22
+ # @param [Array<String>] recipient_paths a collection of
23
+ # profile paths that identify the users who will receive the
24
+ # message
25
+ # @return [void]
26
+ def send_message(subject, body, recipient_paths)
27
+ path = '/people/~/mailbox'
28
+
29
+ message = {
30
+ 'subject' => subject,
31
+ 'body' => body,
32
+ 'recipients' => {
33
+ 'values' => recipient_paths.map do |profile_path|
34
+ { 'person' => { '_path' => "/people/#{profile_path}" } }
35
+ end
36
+ }
37
+ }
38
+ post(path, MultiJson.dump(message), "Content-Type" => "application/json")
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,129 @@
1
+ module LinkedIn
2
+ module Api
3
+
4
+ # Companies API
5
+ #
6
+ # @see https://developer.linkedin.com/docs/company-pages Companies API
7
+ # @see https://developer.linkedin.com/docs/fields/companies Company Fields
8
+ #
9
+ # The following API actions do not have corresponding methods in
10
+ # this module
11
+ #
12
+ # * Permissions Checking Endpoints for Company Shares
13
+ # * GET Suggested Companies to Follow
14
+ # * GET Company Products
15
+ #
16
+ # [(contribute here)](https://github.com/hexgnu/linkedin)
17
+ module Companies
18
+
19
+ # Retrieve a Company Profile
20
+ #
21
+ # @see https://developer.linkedin.com/docs/fields/company-profile Company Profile field
22
+ # @see https://developer.linkedin.com/docs/company-pages#company_profile Company Profile
23
+ #
24
+ # @macro company_path_options
25
+ # @option options [String] :scope
26
+ # @option options [String] :type
27
+ # @option options [String] :count
28
+ # @option options [String] :start
29
+ # @return [LinkedIn::Mash]
30
+ def company(options = {})
31
+ path = company_path(options)
32
+ simple_query(path, options)
33
+ end
34
+
35
+ # Retrieve a feed of event items for a Company
36
+ #
37
+ # @see https://developer.linkedin.com/docs/company-pages#get_update Get Specific Company Update
38
+ #
39
+ # @macro company_path_options
40
+ # @option options [String] :event-type
41
+ # @option options [String] :count
42
+ # @option options [String] :start
43
+ # @return [LinkedIn::Mash]
44
+ def company_updates(options={})
45
+ path = "#{company_path(options)}/updates"
46
+ simple_query(path, options)
47
+ end
48
+
49
+ # Retrieve statistics for a particular company page
50
+ #
51
+ # Permissions: rw_company_admin
52
+ #
53
+ # @see https://developer.linkedin.com/docs/company-pages#statistics Get Company Statistics
54
+ #
55
+ # @macro company_path_options
56
+ # @return [LinkedIn::Mash]
57
+ def company_statistics(options={})
58
+ path = "#{company_path(options)}/company-statistics"
59
+ simple_query(path, options)
60
+ end
61
+
62
+ # Retrieve comments on a particular company update:
63
+ #
64
+ # @see https://developer.linkedin.com/docs/company-pages#get_update_comments Get comments for a specific Company update
65
+ #
66
+ # @param [String] update_key a update/update-key representing a
67
+ # particular company update
68
+ # @macro company_path_options
69
+ # @return [LinkedIn::Mash]
70
+ def company_updates_comments(update_key, options={})
71
+ path = "#{company_path(options)}/updates/key=#{update_key}/update-comments"
72
+ simple_query(path, options)
73
+ end
74
+
75
+ # Retrieve likes on a particular company update:
76
+ #
77
+ # @see https://developer.linkedin.com/docs/company-pages#get_update_likes Get likes for a specific Company update
78
+ #
79
+ # @param [String] update_key a update/update-key representing a
80
+ # particular company update
81
+ # @macro company_path_options
82
+ # @return [LinkedIn::Mash]
83
+ def company_updates_likes(update_key, options={})
84
+ path = "#{company_path(options)}/updates/key=#{update_key}/likes"
85
+ simple_query(path, options)
86
+ end
87
+
88
+ # Create a share for a company that the authenticated user
89
+ # administers
90
+ #
91
+ # Permissions: rw_company_admin
92
+ #
93
+ # @see https://developer.linkedin.com/docs/company-pages#company_share Create a company share
94
+ # @see https://developer.linkedin.com/docs/company-pages#targetting_shares Targeting company shares
95
+ #
96
+ # @param [String] company_id Company ID
97
+ # @macro share_input_fields
98
+ # @return [void]
99
+ def add_company_share(company_id, share)
100
+ path = "/companies/#{company_id}/shares"
101
+ defaults = { visibility: { code: 'anyone' } }
102
+ post(path, MultiJson.dump(defaults.merge(share)), "Content-Type" => "application/json")
103
+ end
104
+
105
+ # (Create) authenticated user starts following a company
106
+ #
107
+ # @see http://developer.linkedin.com/documents/company-follow-and-suggestions
108
+ #
109
+ # @param [String] company_id Company ID
110
+ # @return [void]
111
+ def follow_company(company_id)
112
+ path = "/people/~/following/companies"
113
+ body = { id: company_id }
114
+ post(path, MultiJson.dump(body), "Content-Type" => "application/json")
115
+ end
116
+
117
+ # (Destroy) authenticated user stops following a company
118
+ #
119
+ # @see http://developer.linkedin.com/documents/company-follow-and-suggestions
120
+ #
121
+ # @param [String] company_id Company ID
122
+ # @return [void]
123
+ def unfollow_company(company_id)
124
+ path = "/people/~/following/companies/id=#{company_id}"
125
+ delete(path)
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,115 @@
1
+ module LinkedIn
2
+ module Api
3
+
4
+ # Groups API
5
+ #
6
+ # @see http://developer.linkedin.com/documents/groups-api Groups API
7
+ # @see http://developer.linkedin.com/documents/groups-fields Groups Fields
8
+ #
9
+ # The following API actions do not have corresponding methods in
10
+ # this module
11
+ #
12
+ # * PUT Change my Group Settings
13
+ # * POST Change my Group Settings
14
+ # * DELETE Leave a group
15
+ # * PUT Follow/unfollow a Group post
16
+ # * PUT Flag a Post as a Promotion or Job
17
+ # * DELETE Delete a Post
18
+ # * DELETE Flag a post as inappropriate
19
+ # * DELETE A comment or flag comment as inappropriate
20
+ # * DELETE Remove a Group Suggestion
21
+ #
22
+ # [(contribute here)](https://github.com/hexgnu/linkedin)
23
+ module Groups
24
+
25
+ # Retrieve group suggestions for the current user
26
+ #
27
+ # Permissions: r_fullprofile
28
+ #
29
+ # @see http://developer.linkedin.com/documents/job-bookmarks-and-suggestions
30
+ #
31
+ # @macro person_path_options
32
+ # @return [LinkedIn::Mash]
33
+ def group_suggestions(options = {})
34
+ path = "#{person_path(options)}/suggestions/groups"
35
+ simple_query(path, options)
36
+ end
37
+
38
+ # Retrieve the groups a current user belongs to
39
+ #
40
+ # Permissions: rw_groups
41
+ #
42
+ # @see http://developer.linkedin.com/documents/groups-api
43
+ #
44
+ # @macro person_path_options
45
+ # @return [LinkedIn::Mash]
46
+ def group_memberships(options = {})
47
+ path = "#{person_path(options)}/group-memberships"
48
+ simple_query(path, options)
49
+ end
50
+
51
+ # Retrieve the profile of a group
52
+ #
53
+ # Permissions: rw_groups
54
+ #
55
+ # @see http://developer.linkedin.com/documents/groups-api
56
+ #
57
+ # @param [Hash] options identifies the group or groups
58
+ # @optio options [String] :id identifier for the group
59
+ # @return [LinkedIn::Mash]
60
+ def group_profile(options)
61
+ path = group_path(options)
62
+ simple_query(path, options)
63
+ end
64
+
65
+ # Retrieve the posts in a group
66
+ #
67
+ # Permissions: rw_groups
68
+ #
69
+ # @see http://developer.linkedin.com/documents/groups-api
70
+ #
71
+ # @param [Hash] options identifies the group or groups
72
+ # @optio options [String] :id identifier for the group
73
+ # @optio options [String] :count
74
+ # @optio options [String] :start
75
+ # @return [LinkedIn::Mash]
76
+ def group_posts(options)
77
+ path = "#{group_path(options)}/posts"
78
+ simple_query(path, options)
79
+ end
80
+
81
+ # @deprecated Use {#add_group_share} instead
82
+ def post_group_discussion(group_id, discussion)
83
+ warn 'Use add_group_share over post_group_discussion. This will be taken out in future versions'
84
+ add_group_share(group_id, discussion)
85
+ end
86
+
87
+ # Create a share for a company that the authenticated user
88
+ # administers
89
+ #
90
+ # Permissions: rw_groups
91
+ #
92
+ # @see http://developer.linkedin.com/documents/groups-api#create
93
+ #
94
+ # @param [String] group_id Group ID
95
+ # @macro share_input_fields
96
+ # @return [void]
97
+ def add_group_share(group_id, share)
98
+ path = "/groups/#{group_id}/posts"
99
+ post(path, MultiJson.dump(share), "Content-Type" => "application/json")
100
+ end
101
+
102
+ # (Update) User joins, or requests to join, a group
103
+ #
104
+ # @see http://developer.linkedin.com/documents/groups-api#membergroups
105
+ #
106
+ # @param [String] group_id Group ID
107
+ # @return [void]
108
+ def join_group(group_id)
109
+ path = "/people/~/group-memberships/#{group_id}"
110
+ body = {'membership-state' => {'code' => 'member' }}
111
+ put(path, MultiJson.dump(body), "Content-Type" => "application/json")
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,64 @@
1
+ module LinkedIn
2
+ module Api
3
+
4
+ # Jobs API
5
+ #
6
+ # @see http://developer.linkedin.com/documents/job-lookup-api-and-fields Job Lookup API and Fields
7
+ # @see http://developer.linkedin.com/documents/job-bookmarks-and-suggestions Job Bookmarks and Suggestions
8
+ #
9
+ # The following API actions do not have corresponding methods in
10
+ # this module
11
+ #
12
+ # * DELETE a Job Bookmark
13
+ #
14
+ # [(contribute here)](https://github.com/hexgnu/linkedin)
15
+ module Jobs
16
+
17
+ # Retrieve likes on a particular company update:
18
+ #
19
+ # @see http://developer.linkedin.com/reading-company-shares
20
+ #
21
+ # @param [Hash] options identifies the job
22
+ # @option options [String] id unique identifier for a job
23
+ # @return [LinkedIn::Mash]
24
+ def job(options = {})
25
+ path = jobs_path(options)
26
+ simple_query(path, options)
27
+ end
28
+
29
+ # Retrieve the current members' job bookmarks
30
+ #
31
+ # @see http://developer.linkedin.com/documents/job-bookmarks-and-suggestions
32
+ #
33
+ # @macro person_path_options
34
+ # @return [LinkedIn::Mash]
35
+ def job_bookmarks(options = {})
36
+ path = "#{person_path(options)}/job-bookmarks"
37
+ simple_query(path, options)
38
+ end
39
+
40
+ # Retrieve job suggestions for the current user
41
+ #
42
+ # @see http://developer.linkedin.com/documents/job-bookmarks-and-suggestions
43
+ #
44
+ # @macro person_path_options
45
+ # @return [LinkedIn::Mash]
46
+ def job_suggestions(options = {})
47
+ path = "#{person_path(options)}/suggestions/job-suggestions"
48
+ simple_query(path, options)
49
+ end
50
+
51
+ # Create a job bookmark for the authenticated user
52
+ #
53
+ # @see http://developer.linkedin.com/documents/job-bookmarks-and-suggestions
54
+ #
55
+ # @param [String] job_id Job ID
56
+ # @return [void]
57
+ def add_job_bookmark(job_id)
58
+ path = "/people/~/job-bookmarks"
59
+ body = {'job' => {'id' => job_id}}
60
+ post(path, MultiJson.dump(body), "Content-Type" => "application/json")
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,73 @@
1
+ module LinkedIn
2
+ module Api
3
+
4
+ # People APIs
5
+ #
6
+ #
7
+ # @see https://developer.linkedin.com/docs/fields/basic-profile Profile Fields
8
+ # @see http://developer.linkedin.com/documents/field-selectors Field Selectors
9
+ # @see http://developer.linkedin.com/documents/accessing-out-network-profiles Accessing Out of Network Profiles
10
+ module People
11
+
12
+ # Retrieve a member's LinkedIn profile.
13
+ #
14
+ # Permissions: r_basicprofile, r_fullprofile
15
+ #
16
+ # @see https://developer.linkedin.com/docs/signin-with-linkedin#content-par_componenttabbedlist_resource_1_resourceparagraph_6
17
+ # @macro person_path_options
18
+ # @option options [string] :secure-urls if 'true' URLs in responses will be HTTPS
19
+ # @return [LinkedIn::Mash]
20
+ def profile(options={})
21
+ path = person_path(options)
22
+ simple_query(path, options)
23
+ end
24
+
25
+ # Retrieve a list of 1st degree connections for a user who has
26
+ # granted access to his/her account
27
+ #
28
+ # Permissions: r_network
29
+ #
30
+ # @see http://developer.linkedin.com/documents/connections-api
31
+ #
32
+ # @macro person_path_options
33
+ # @return [LinkedIn::Mash]
34
+ def connections(options={})
35
+ path = "#{person_path(options)}/connections"
36
+ simple_query(path, options)
37
+ end
38
+
39
+ # Retrieve a list of the latest set of 1st degree connections for a
40
+ # user
41
+ #
42
+ # Permissions: r_network
43
+ #
44
+ # @see http://developer.linkedin.com/documents/connections-api
45
+ #
46
+ # @param [String] modified_since timestamp indicating since when
47
+ # you want to retrieve new connections
48
+ # @macro person_path_options
49
+ # @return [LinkedIn::Mash]
50
+ def new_connections(modified_since, options={})
51
+ options.merge!('modified' => 'new', 'modified-since' => modified_since)
52
+ path = "#{person_path(options)}/connections"
53
+ simple_query(path, options)
54
+ end
55
+
56
+ # Retrieve the picture url
57
+ # http://api.linkedin.com/v1/people/~/picture-urls::(original)
58
+ #
59
+ # Permissions: r_network
60
+ #
61
+ # @options [String] :id, the id of the person for whom you want the profile picture
62
+ # @options [String] :picture_size, default: 'original'
63
+ # @options [String] :secure, default: 'false', options: ['false','true']
64
+ #
65
+ # example for use in code: client.picture_urls(:id => 'id_of_connection')
66
+ def picture_urls(options={})
67
+ picture_size = options.delete(:picture_size) || 'original'
68
+ path = "#{picture_urls_path(options)}::(#{picture_size})"
69
+ simple_query(path, options)
70
+ end
71
+ end
72
+ end
73
+ end