xing_api_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +76 -0
  5. data/Guardfile +8 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +239 -0
  8. data/Rakefile +1 -0
  9. data/config.yml.sample +7 -0
  10. data/lib/xing_api_client/call/base.rb +23 -0
  11. data/lib/xing_api_client/call/registry.rb +22 -0
  12. data/lib/xing_api_client/call/users_bookmarks_call.rb +36 -0
  13. data/lib/xing_api_client/call/users_call.rb +11 -0
  14. data/lib/xing_api_client/call/users_contact_requests_call.rb +41 -0
  15. data/lib/xing_api_client/call/users_contacts_call.rb +25 -0
  16. data/lib/xing_api_client/call/users_contacts_shared_call.rb +24 -0
  17. data/lib/xing_api_client/call/users_contacts_tags_call.rb +14 -0
  18. data/lib/xing_api_client/call/users_find_by_emails_call.rb +21 -0
  19. data/lib/xing_api_client/call/users_me_id_card_call.rb +9 -0
  20. data/lib/xing_api_client/call/users_network_paths_call.rb +18 -0
  21. data/lib/xing_api_client/call/users_profile_message_call.rb +22 -0
  22. data/lib/xing_api_client/call.rb +12 -0
  23. data/lib/xing_api_client/config.rb +38 -0
  24. data/lib/xing_api_client/object/address.rb +8 -0
  25. data/lib/xing_api_client/object/base.rb +23 -0
  26. data/lib/xing_api_client/object/company.rb +15 -0
  27. data/lib/xing_api_client/object/school.rb +15 -0
  28. data/lib/xing_api_client/object/user.rb +29 -0
  29. data/lib/xing_api_client/object/year_month.rb +28 -0
  30. data/lib/xing_api_client/object.rb +11 -0
  31. data/lib/xing_api_client/request/error.rb +23 -0
  32. data/lib/xing_api_client/request.rb +85 -0
  33. data/lib/xing_api_client/version.rb +3 -0
  34. data/lib/xing_api_client.rb +54 -0
  35. data/spec/spec_helper.rb +107 -0
  36. data/spec/xing_api_client/call/users_bookmarks_call_spec.rb +103 -0
  37. data/spec/xing_api_client/call/users_call_spec.rb +41 -0
  38. data/spec/xing_api_client/call/users_contact_requests_call_spec.rb +130 -0
  39. data/spec/xing_api_client/call/users_contacts_call_spec.rb +45 -0
  40. data/spec/xing_api_client/call/users_contacts_shared_call_spec.rb +45 -0
  41. data/spec/xing_api_client/call/users_contacts_tags_call_spec.rb +20 -0
  42. data/spec/xing_api_client/call/users_find_by_emails_call_spec.rb +37 -0
  43. data/spec/xing_api_client/call/users_me_id_card_call_spec.rb +19 -0
  44. data/spec/xing_api_client/call/users_network_paths_call_spec.rb +37 -0
  45. data/spec/xing_api_client/call/users_profile_message_call_spec.rb +63 -0
  46. data/spec/xing_api_client/config_spec.rb +67 -0
  47. data/spec/xing_api_client/object/user_spec.rb +37 -0
  48. data/spec/xing_api_client/object/year_month_spec.rb +70 -0
  49. data/spec/xing_api_client/request/error_spec.rb +15 -0
  50. data/spec/xing_api_client/request_spec.rb +70 -0
  51. data/spec/xing_api_client_spec.rb +51 -0
  52. data/xing_api_client.gemspec +26 -0
  53. metadata +227 -0
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ .irbrc
3
+ local_*
4
+ .ruby-version
5
+ .rbenv*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ xing_api_client (0.0.1)
5
+ activesupport
6
+ bundler (~> 1.3)
7
+ oauth
8
+ parallel
9
+ rake
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ activesupport (4.0.0)
15
+ i18n (~> 0.6, >= 0.6.4)
16
+ minitest (~> 4.2)
17
+ multi_json (~> 1.3)
18
+ thread_safe (~> 0.1)
19
+ tzinfo (~> 0.3.37)
20
+ atomic (1.1.14)
21
+ celluloid (0.15.2)
22
+ timers (~> 1.1.0)
23
+ coderay (1.0.9)
24
+ diff-lcs (1.2.4)
25
+ ffi (1.9.0)
26
+ formatador (0.2.4)
27
+ guard (2.2.2)
28
+ formatador (>= 0.2.4)
29
+ listen (~> 2.1)
30
+ lumberjack (~> 1.0)
31
+ pry (>= 0.9.12)
32
+ thor (>= 0.18.1)
33
+ guard-rspec (4.0.3)
34
+ guard (>= 2.1.1)
35
+ rspec (~> 2.14)
36
+ i18n (0.6.5)
37
+ listen (2.1.1)
38
+ celluloid (>= 0.15.2)
39
+ rb-fsevent (>= 0.9.3)
40
+ rb-inotify (>= 0.9)
41
+ lumberjack (1.0.4)
42
+ method_source (0.8.2)
43
+ minitest (4.7.5)
44
+ multi_json (1.8.2)
45
+ oauth (0.4.7)
46
+ parallel (0.9.0)
47
+ pry (0.9.12.2)
48
+ coderay (~> 1.0.5)
49
+ method_source (~> 0.8)
50
+ slop (~> 3.4)
51
+ rake (10.1.0)
52
+ rb-fsevent (0.9.3)
53
+ rb-inotify (0.9.2)
54
+ ffi (>= 0.5.0)
55
+ rspec (2.14.1)
56
+ rspec-core (~> 2.14.0)
57
+ rspec-expectations (~> 2.14.0)
58
+ rspec-mocks (~> 2.14.0)
59
+ rspec-core (2.14.6)
60
+ rspec-expectations (2.14.3)
61
+ diff-lcs (>= 1.1.3, < 2.0)
62
+ rspec-mocks (2.14.4)
63
+ slop (3.4.6)
64
+ thor (0.18.1)
65
+ thread_safe (0.1.3)
66
+ atomic
67
+ timers (1.1.0)
68
+ tzinfo (0.3.38)
69
+
70
+ PLATFORMS
71
+ ruby
72
+
73
+ DEPENDENCIES
74
+ guard-rspec
75
+ rspec
76
+ xing_api_client!
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec, all_on_start: true do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Martin Brendel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,239 @@
1
+ # XingApiClient
2
+ The main goal of this Gem is to provide an easy access to the XING API. The XING API uses the OAuth1 standard for the access management and offers calls to access data and functions from user accounts. This Gem encapsulates both by providing methods to handle it in a high level way.
3
+
4
+ Special thanks go to [Jan-Oliver Jahner (jojahner)](https://github.com/jojahner) and [Björn Jensen (mirouhh)](https://github.com/mirouhh).
5
+
6
+ ## Requirements
7
+
8
+ Tested with ruby 1.9.3p448 and 2.0.0-p0.
9
+
10
+ ## Quickstart
11
+ ### Make a handshake
12
+ ```ruby
13
+ # Require the Gem
14
+ require('xing_api_client')
15
+
16
+ # Get a consumer key and secret from https://dev.xing.com/applications and set up the configuration
17
+ XingApiClient::Config.set(consumer_key: '12345', consumer_secret: 'abcde')
18
+
19
+ # Initialize the handshake
20
+ request_params = XingApiClient.request_params
21
+ puts "Use your browser to open #{request_params[:auth_url]}"
22
+
23
+ # Verify the pin
24
+ puts "Please enter the pin:"
25
+ pin = gets.chomp.strip
26
+
27
+ # Authorize the handshake and get the token and secret
28
+ authorized_params = XingApiClient.authorize(request_params[:request_token], pin)
29
+ puts authorized_params.inspect # { access_token: 'abcde', secret: '12345' }
30
+
31
+ # Initialize a client
32
+ client = XingApiClient.new(authorized_params[:access_token], authorized_params[:secret])
33
+
34
+ # Make a request to load your user data
35
+ puts client.request.get_users.inspect
36
+ ```
37
+
38
+ ## Before you start
39
+ To get access to the XING API, you need a consumer key and a consumer secret. To get those you have to login to the Dev-Portal http://dev.xing.com and create a new app. Now you have a test-consumer-key which can use all calls that are listed in the documentation https://dev.xing.com/docs/resources .
40
+ After you have developed your app, you can request a production-consumer-key by using the ‘Get a production key’-Button on the app management site (https://dev.xing.com/applications).
41
+
42
+ ## Configuration
43
+ The default configuration:
44
+
45
+ ```ruby
46
+ {
47
+ host: 'https://api.xing.com',
48
+ request_token_path: '/v1/request_token',
49
+ authorize_path: '/v1/authorize',
50
+ access_token_path: '/v1/access_token',
51
+ consumer_key: nil,
52
+ consumer_secret: nil,
53
+ callback_url: nil # The callback URL for the pin. If it is blank, you user hat to enter the pin manually
54
+ }
55
+ ```
56
+
57
+ You can add/overwrite configuration values in four different ways:
58
+
59
+ ### Use a Hash
60
+ ```ruby
61
+ XingApiClient::Config.set(consumer_key: '12345', host: 'abcde')
62
+ ```
63
+
64
+ ### Use a YAML-File
65
+ ```ruby
66
+ XingApiClient::Config.load_file('path/config.yml')
67
+ ```
68
+
69
+ ### Use Environment variables
70
+
71
+ ```ruby
72
+ XingApiClient::Config.load_env
73
+ ```
74
+
75
+ Loads this enviroment variables:
76
+ - XINGAPICLIENT_HOST
77
+ - XINGAPICLIENT_REQUEST_TOKEN_PATH
78
+ - XINGAPICLIENT_AUTHORIZE_PATH
79
+ - XINGAPICLIENT_ACCESS_TOKEN_PATH
80
+ - XINGAPICLIENT_CONSUMER_KEY
81
+ - XINGAPICLIENT_CONSUMER_SECRET
82
+ - XINGAPICLIENT_CALLBACK_URL
83
+
84
+ If you set a prefix, it replaces the part 'XINGAPICLIENT'. Empty values will be ignored.
85
+
86
+ ### Paste some values to the initialization
87
+ ```ruby
88
+ configuration_values = {
89
+ consumer_key: '12345',
90
+ consumer_secret: 'abcde',
91
+ }
92
+
93
+ XingApiClient.new('access_token', 'access_token_secret', configuration_values)
94
+ ```
95
+
96
+ Here are only the values 'consumer_key' and 'consumer_secret' available.
97
+
98
+ ## Handshake
99
+ Before you can start using the gem you need to make the handshake for every developer. There are two different ways:
100
+
101
+ ### Pin
102
+ The user has to enter the pin manually if no callback URL is configured.
103
+ ```ruby
104
+ # Get a consumer key and secret from https://dev.xing.com/applications and set up the configuration
105
+ XingApiClient::Config.set(consumer_key: '12345', consumer_secret: 'abcde')
106
+
107
+ # Initialize the handshake
108
+ request_params = XingApiClient.request_params
109
+ puts "Use your browser to open #{request_params[:auth_url]}"
110
+
111
+ # Verify the pin
112
+ puts "Please enter the pin:"
113
+ pin = gets.chomp.strip
114
+
115
+ # Authorize the handshake and get the token and secret
116
+ authorized_params = XingApiClient.authorize(request_params[:request_token], pin)
117
+ puts authorized_params.inspect # { access_token: 'abcde', secret: '12345' }
118
+ ```
119
+
120
+ ### Callback
121
+ If a callback URL is defined this will be use to send the pin as a parameter.
122
+
123
+ ```ruby
124
+ # Get a consumer key and secret from https://dev.xing.com/applications and set up the configuration
125
+ XingApiClient::Config.set(consumer_key: '12345', consumer_secret: 'abcde')
126
+
127
+ request_params = XingApiClient.request_params
128
+
129
+ # You need to save the token somewhere
130
+ session[:token] = request_params[:request_token]
131
+
132
+ # Initialize the handshake
133
+ redirect_to request_params[:auth_url]
134
+ ```
135
+
136
+ The user gets redirected to the handshake dialog. After he has accepted the handshake the url cets called with the parameter 'oauth_verifier' witch contains the pin.
137
+
138
+ ```ruby
139
+ authorized_params = XingApiClient.authorize(session[:token], params[:oauth_verifier])
140
+ puts authorized_params.inspect # { access_token: 'abcde', secret: '12345' }
141
+ ```
142
+
143
+
144
+ ## Make calls
145
+ After setting up the configuration and making the handshake you can make calls in the scope of the user.
146
+
147
+ ```ruby
148
+ # Don't forget to configurate your client before you initialize an object
149
+
150
+ client = XingApiClient.new('ACCESS_TOKEN', 'SECRET')
151
+ client.request.call_methods.keys # [:get_users, :get_users_contact_requests, :get_users_contacts, ...]
152
+ client.request.get_users(id: 'me')
153
+ ```
154
+
155
+ ## Available calls
156
+ ### User Profiles
157
+ - [x] GET /v1/users/:id
158
+ - [x] GET /v1/users/me
159
+ - [x] GET /v1/users/me/id_card
160
+ - [x] GET /v1/users/find_by_emails
161
+
162
+ ### Jobs
163
+ - [ ] ~~GET /v1/jobs/:id (experimental)~~
164
+ - [ ] ~~GET /v1/jobs/find (experimental)~~
165
+ - [ ] ~~GET /v1/users/:user_id/jobs/recommendations (experimental)~~
166
+
167
+ ### Messages
168
+ - [ ] GET /v1/users/:user_id/conversations
169
+ - [ ] POST /v1/users/:user_id/conversations
170
+ - [ ] ~~GET /v1/users/me/conversations/valid_recipients/:id (experimental)~~
171
+ - [ ] GET /v1/users/:user_id/conversations/:id
172
+ - [ ] ~~GET /v1/user…ations/:conversation_id/attachments (experimental)~~
173
+ - [ ] ~~GET /v1/user…ns/:conversation_id/attachments/:id (experimental)~~
174
+ - [ ] ~~POST /v1/user…rsation_id/attachments/:id/download (experimental)~~
175
+ - [ ] PUT /v1/users/:user_id/conversations/:id/read
176
+ - [ ] ~~PUT /v1/user…s/:conversation_id/participants/:id (experimental)~~
177
+ - [ ] GET /v1/user…ersations/:conversation_id/messages
178
+ - [ ] GET /v1/user…tions/:conversation_id/messages/:id
179
+ - [ ] PUT /v1/user…/:conversation_id/messages/:id/read
180
+ - [ ] DELETE /v1/user…/:conversation_id/messages/:id/read
181
+ - [ ] POST /v1/user…ersations/:conversation_id/messages
182
+ - [ ] DELETE /v1/users/:user_id/conversations/:id
183
+
184
+ ### Profile Messages
185
+ - [x] GET /v1/users/:user_id/profile_message
186
+ - [x] PUT /v1/users/:user_id/profile_message
187
+
188
+ ### Contacts
189
+ - [x] GET /v1/users/:user_id/contacts
190
+ - [ ] ~~GET /v1/users/me/contact_ids (experimental)~~
191
+ - [x] GET /v1/users/:user_id/contacts/:contact_id/tags
192
+ - [x] GET /v1/users/:user_id/contacts/shared
193
+
194
+ ### Contact Requests
195
+ - [x] GET /v1/users/:user_id/contact_requests
196
+ - [x] POST /v1/users/:user_id/contact_requests
197
+ - [x] DELETE /v1/users/:user_id/contact_requests/:id
198
+ - [x] GET /v1/users/:user_id/contact_requests/sent
199
+ - [x] PUT /v1/users/:user_id/contact_requests/:id/accept
200
+
201
+ ### Contact Path
202
+ - [x] GET /v1/users/:user_id/network/:other_user_id/paths
203
+
204
+ ### Bookmarks
205
+ - [x] GET /v1/users/:user_id/bookmarks
206
+ - [x] PUT /v1/users/:user_id/bookmarks/:id
207
+ - [x] DELETE /v1/users/:user_id/bookmarks/:id
208
+
209
+ ### Network Feed
210
+ - [ ] GET /v1/users/:user_id/network_feed
211
+ - [ ] GET /v1/users/:id/feed
212
+ - [ ] POST /v1/users/:id/status_message
213
+ - [ ] ~~POST /v1/users/me/share/link (experimental)~~
214
+ - [ ] GET /v1/activities/:id
215
+ - [ ] POST /v1/activities/:id/share
216
+ - [ ] DELETE /v1/activities/:id
217
+ - [ ] GET /v1/activities/:activity_id/comments
218
+ - [ ] POST /v1/activities/:activity_id/comments
219
+ - [ ] DELETE /v1/activities/:activity_id/comments/:id
220
+ - [ ] GET /v1/activities/:activity_id/likes
221
+ - [ ] PUT /v1/activities/:activity_id/like
222
+ - [ ] DELETE /v1/activities/:activity_id/like
223
+
224
+ ### Profile Visits
225
+ - [ ] GET /v1/users/:user_id/visits
226
+ - [ ] POST /v1/users/:user_id/visits
227
+
228
+ ### Recommendations
229
+ - [ ] GET /v1/users/:user_id/network/recommendations
230
+ - [ ] DELETE /v1/users/:user_id/network/recommendations/user/:id
231
+
232
+ ### Invitations
233
+ - [ ] ~~POST /v1/users/invite (experimental)~~
234
+
235
+ ### Geo Locations
236
+ - [ ] GET /v1/users/:user_id/nearby_users
237
+ - [ ] PUT /v1/users/:user_id/geo_location
238
+
239
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/config.yml.sample ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ :consumer_key: [PLEASE CHANGE]
3
+ :consumer_secret: [PLEASE CHANGE]
4
+ :callback_url:
5
+ :host: https://api.xing.com
6
+ :request_token_path: /v1/request_token
7
+ :authorize_path: /v1/authorize
@@ -0,0 +1,23 @@
1
+ class XingApiClient
2
+ module Call
3
+ module Base
4
+
5
+ private
6
+ def request_loop(total, result, offset, requested_limit, max_limit_per_call = 100)
7
+ offset ||= 0
8
+
9
+ if (requested_limit.nil? || requested_limit.to_i > max_limit_per_call) && total > max_limit_per_call
10
+
11
+ local_limit = requested_limit.nil? ? total : [requested_limit.to_i, total].min
12
+ steps = (1...(local_limit / max_limit_per_call.to_f).ceil).to_a
13
+ steps.map!{ |s| s * max_limit_per_call + offset }
14
+
15
+ yield result, steps
16
+
17
+ end
18
+ result.define_singleton_method :total, -> { total }
19
+ result
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ class XingApiClient
2
+ module Call
3
+ module Registry
4
+ def self.register_call_methods(target_class)
5
+ call_methods = {}
6
+
7
+ names = Dir.entries(File.dirname(__FILE__)).select{ |file| file.match(/_call.rb$/)}
8
+ names.map!{ |name| name.gsub(/.rb$/, '') }
9
+
10
+ names.each do |name|
11
+ constant = eval('XingApiClient::Call::' + name.split('_').map{ |s| "#{s[0].upcase}#{s[1..-1]}"}.join)
12
+ target_class.send :include, constant
13
+ call_methods[constant.instance_methods.first] = constant
14
+ end
15
+
16
+ target_class.send(:define_method, :call_methods) do
17
+ call_methods
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,36 @@
1
+ class XingApiClient
2
+ module Call
3
+ module UsersBookmarksCall
4
+ include Base
5
+
6
+ def get_users_bookmarks(options = {})
7
+
8
+ id = options[:id] || 'me'
9
+ offset = options[:offset] || 0
10
+ fields = options[:fields]
11
+ limit = options[:limit]
12
+
13
+ result = make_request!(:get, "v1/users/#{id}/bookmarks", { limit: (limit || 100), offset: offset, user_fields: fields }, array_keys: "bookmarks")
14
+
15
+ request_loop(result["total"].to_i, result["items"], offset, limit, 100) do |result, steps|
16
+ Parallel.map(steps, in_threads: 2) do |offset|
17
+ make_request!(:get, "v1/users/#{id}/bookmarks", { limit: 100, offset: offset, user_fields: fields }, array_keys: ["bookmarks", "items"])
18
+ end.each { |r| result.concat r }
19
+
20
+ end
21
+ end
22
+
23
+ def put_users_bookmarks(bookmark_id, options = {})
24
+ id = options[:id] || 'me'
25
+
26
+ make_request!(:put, "v1/users/#{id}/bookmarks/#{bookmark_id}", {}, allowed_codes: 204)
27
+ end
28
+
29
+ def delete_users_bookmarks(bookmark_id, options = {})
30
+ id = options[:id] || 'me'
31
+
32
+ make_request!(:delete, "v1/users/#{id}/bookmarks/#{bookmark_id}", {}, allowed_codes: 204)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ class XingApiClient
2
+ module Call
3
+ module UsersCall
4
+ def get_users(options = {})
5
+ id = options[:id] || 'me'
6
+
7
+ make_request!(:get, "v1/users/#{id}", {}, array_keys: "users").first
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ class XingApiClient
2
+ module Call
3
+ module UsersContactRequestsCall
4
+ include Base
5
+
6
+ def get_users_contact_requests(options = {})
7
+ id = options[:id] || 'me'
8
+ offset = options[:offset] || 0
9
+ limit = options[:limit]
10
+ fields = options[:fields]
11
+
12
+ make_request!(:get, "v1/users/#{id}/contact_requests", { limit: (limit || 100), offset: offset, user_fields: fields }, array_keys: ["contact_requests"])
13
+ end
14
+
15
+
16
+ def delete_users_contact_requests(recipient_id, options = {})
17
+ id = options[:id] || 'me'
18
+
19
+ make_request!(:delete, "v1/users/#{id}/contact_requests/#{recipient_id}", {}, allowed_codes: 204)
20
+ end
21
+
22
+ def post_users_contact_requests(recipient_id, message)
23
+ make_request!(:post, "v1/users/#{recipient_id}/contact_requests", { message: message }, content_type: 'text', allowed_codes: 201)
24
+ end
25
+
26
+ def put_users_contact_requests_accept(recipient_id, options = {})
27
+ id = options[:id] || 'me'
28
+
29
+ make_request!(:put, "v1/users/#{id}/contact_requests/#{recipient_id}/accept", {}, allowed_codes: 204)
30
+ end
31
+
32
+ def get_users_contact_requests_sent(options = {})
33
+ id = options[:id] || 'me'
34
+ offset = options[:offset] || 0
35
+ limit = options[:limit]
36
+
37
+ make_request!(:get, "v1/users/#{id}/contact_requests/sent", {}, array_keys: "contact_requests")
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ class XingApiClient
2
+ module Call
3
+ module UsersContactsCall
4
+ include Base
5
+
6
+ def get_users_contacts(options = {})
7
+ id = options[:id] || 'me'
8
+ offset = options[:offset]
9
+ limit = options[:limit]
10
+ fields = options[:fields]
11
+
12
+ params = { user_fields: fields }
13
+ params.merge!(order_by: options[:order]) if options[:order] == 'last_name'
14
+
15
+ result = make_request!(:get, "v1/users/#{id}/contacts", params.merge(limit: (limit || 100), offset: offset), array_keys: "contacts")
16
+
17
+ request_loop(result["total"].to_i, result["users"], offset, limit, 100) do |result, steps|
18
+ Parallel.map(steps, in_threads: 2) do |offset|
19
+ make_request!(:get, "v1/users/#{id}/contacts", params.merge(limit: 100, offset: offset), array_keys: ["contacts", "users"])
20
+ end.each { |r| result.concat r }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ class XingApiClient
2
+ module Call
3
+ module UsersContactsSharedCall
4
+ include Base
5
+
6
+ def get_users_contacts_shared(other_user_id, options = {})
7
+ offset = options[:offset]
8
+ limit = options[:limit]
9
+ fields = options[:fields]
10
+
11
+ params = { user_fields: fields }
12
+ params.merge!(order_by: options[:order]) if options[:order] == 'last_name'
13
+
14
+ result = make_request!(:get, "v1/users/#{other_user_id}/contacts/shared", params.merge(limit: (limit || 100), offset: offset), array_keys: "shared_contacts")
15
+
16
+ request_loop(result["total"].to_i, result["users"], offset, limit, 100) do |result, steps|
17
+ Parallel.map(steps, in_threads: 2) do |offset|
18
+ make_request!(:get, "v1/users/#{other_user_id}/contacts/shared", params.merge(limit: 100, offset: offset), array_keys: ["shared_contacts", "users"])
19
+ end.each { |r| result.concat r }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ class XingApiClient
2
+ module Call
3
+ module UsersContactsTagsCall
4
+ def get_users_contacts_tags(contact_id)
5
+ request = make_request!(:get, "v1/users/me/contacts/#{contact_id}/tags", {}, array_keys: "tags")
6
+
7
+ request["items"].tap do |tags|
8
+ tags.map!{ |t| t["tag"] }.sort!
9
+ tags.define_singleton_method :total, -> { request["total"].to_i }
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ class XingApiClient
2
+ module Call
3
+ module UsersFindByEmailsCall
4
+ include Base
5
+
6
+ def get_users_find_by_emails(emails, options = {})
7
+ params = {
8
+ emails: emails,
9
+ user_fields: options[:fields]
10
+ }
11
+ params.merge!(hash_function: options[:hash_function]) if options[:hash_function] == 'MD5'
12
+
13
+ result = make_request!(:get, "v1/users/find_by_emails", params, array_keys: ["results"])
14
+
15
+ result["items"].tap do |collection|
16
+ collection.define_singleton_method :total, -> { result["total"] }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ class XingApiClient
2
+ module Call
3
+ module UsersMeIdCardCall
4
+ def get_users_me_id_card
5
+ make_request!(:get, "v1/users/me/id_card", {}, array_keys: ["id_card"])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ class XingApiClient
2
+ module Call
3
+ module UsersNetworkPathsCall
4
+ def get_users_network_paths(other_user_id, options = {})
5
+ id = options[:id] || 'me'
6
+ offset = options[:offset] || 0
7
+ limit = options[:limit]
8
+ fields = options[:fields]
9
+
10
+ result = make_request!(:get, "v1/users/#{id}/network/#{other_user_id}/paths", {}, array_keys: ["contact_paths"])
11
+ result['paths'].tap do |collection|
12
+ collection.define_singleton_method :distance, -> { result["distance"].to_i }
13
+ collection.define_singleton_method :total, -> { result["total"].to_i }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ class XingApiClient
2
+ module Call
3
+ module UsersProfileMessageCall
4
+ include Base
5
+
6
+ def get_users_profile_message(options = {})
7
+ id = options[:id] || 'me'
8
+
9
+ make_request!(:get, "v1/users/#{id}/profile_message", {}, array_keys: ["profile_message"])
10
+ end
11
+
12
+ def put_users_profile_message(message, options = {})
13
+ id = options[:id] || 'me'
14
+
15
+ params = { message: message }
16
+ params.merge!( :public => options[:public] ) if options[:public]
17
+
18
+ make_request!(:put, "v1/users/#{id}/profile_message", params, allowed_codes: 204 )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ Dir[File.dirname(__FILE__) + '/call/*.rb'].each { |name| require(name) }
2
+
3
+ class XingApiClient
4
+ module Call
5
+ def self.included(base)
6
+ XingApiClient::Call::Registry.register_call_methods base
7
+ end
8
+ end
9
+ end
10
+
11
+
12
+