xing_api_client 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/Gemfile.lock +66 -54
- data/README.md +2 -0
- data/lib/xing_api_client.rb +32 -4
- data/lib/xing_api_client/call/base.rb +6 -0
- data/lib/xing_api_client/call/users_network_recommendations_call.rb +22 -0
- data/lib/xing_api_client/request.rb +13 -30
- data/lib/xing_api_client/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/xing_api_client/call/users_network_recommendations_spec.rb +46 -0
- data/spec/xing_api_client/object/company_spec.rb +1 -1
- data/spec/xing_api_client/object/user_spec.rb +1 -1
- data/spec/xing_api_client/request_spec.rb +17 -17
- data/spec/xing_api_client_spec.rb +27 -8
- data/xing_api_client.gemspec +5 -2
- metadata +74 -29
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NmFmNjJlOThlZWM3YjA1M2ZmYzNlMzk1ZWZjYTcyMjFlOGYxNzdkYg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 75e534abd891af04eb014e3983a57023e8963b64
|
4
|
+
data.tar.gz: e919f7ff97365327acc31c13c2be08c1fcf64e79
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZGJhMzhhNjQ1YzhmMDQ2ZDhhZmFjMjE3ZjUxNWVkOGNmOGNmZDI4ZGIzMjI3
|
11
|
-
NGQ5M2Y3YmMyMTBmYzgwMDE2MzY4NmY3MjVkOGI2NTE4NDlhYTU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NjYwMTFmOGMyZTJmNGE0MDQ4Yjg2MjQ4NmI3ZDE2OGNiZjE3ZmQxYmI3MDQz
|
14
|
-
NTFiOTE3MDAzNDRiN2UyNTI2NDI5NWJhYTBiNWI3YWM3YWU5ZDQwNzczNTIw
|
15
|
-
YTE3OTIwYmM0NTE0ZjQ1YTU3MmQ4NzI2NzhjNWI4NjlhNzc2MmE=
|
6
|
+
metadata.gz: cac9998eea8762b84fa47ca56a163df9fbcd4e955f5c1181d6d363a3dd4314c0f353f399c93ecfc57d7f88823a90044283969fc27dbb95670dd845aa9af667c5
|
7
|
+
data.tar.gz: e007a8ca2c70f9b65f43592eaca28e840f45b36bd01aadfd0c9d7d50432c1f58db10e567939fdb1bc9e496796587bd0da8cdb73874b1c6bb005fdd6ba2d4c8d5
|
data/Gemfile.lock
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
xing_api_client (0.0.
|
4
|
+
xing_api_client (0.0.4)
|
5
5
|
activesupport
|
6
|
-
bundler
|
6
|
+
bundler
|
7
|
+
faraday
|
8
|
+
faraday_middleware
|
7
9
|
mimemagic
|
8
10
|
multipart-post
|
9
11
|
oauth
|
10
12
|
parallel
|
11
13
|
rake
|
14
|
+
simple_oauth
|
12
15
|
|
13
16
|
GEM
|
14
17
|
remote: https://rubygems.org/
|
15
18
|
specs:
|
16
|
-
activesupport (4.1.
|
19
|
+
activesupport (4.1.4)
|
17
20
|
i18n (~> 0.6, >= 0.6.9)
|
18
21
|
json (~> 1.7, >= 1.7.7)
|
19
22
|
minitest (~> 5.1)
|
@@ -21,77 +24,86 @@ GEM
|
|
21
24
|
tzinfo (~> 1.1)
|
22
25
|
celluloid (0.15.2)
|
23
26
|
timers (~> 1.1.0)
|
24
|
-
coderay (1.0
|
25
|
-
columnize (0.8.9)
|
27
|
+
coderay (1.1.0)
|
26
28
|
coveralls (0.7.0)
|
27
29
|
multi_json (~> 1.3)
|
28
30
|
rest-client
|
29
31
|
simplecov (>= 0.7)
|
30
32
|
term-ansicolor
|
31
33
|
thor
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
guard (2.2.2)
|
34
|
+
diff-lcs (1.2.5)
|
35
|
+
docile (1.1.5)
|
36
|
+
faraday (0.9.0)
|
37
|
+
multipart-post (>= 1.2, < 3)
|
38
|
+
faraday_middleware (0.9.1)
|
39
|
+
faraday (>= 0.7.4, < 0.10)
|
40
|
+
ffi (1.9.3)
|
41
|
+
formatador (0.2.5)
|
42
|
+
guard (2.6.1)
|
42
43
|
formatador (>= 0.2.4)
|
43
|
-
listen (~> 2.
|
44
|
+
listen (~> 2.7)
|
44
45
|
lumberjack (~> 1.0)
|
45
46
|
pry (>= 0.9.12)
|
46
47
|
thor (>= 0.18.1)
|
47
|
-
guard-rspec (4.
|
48
|
-
guard (
|
49
|
-
rspec (
|
50
|
-
i18n (0.6.
|
48
|
+
guard-rspec (4.3.1)
|
49
|
+
guard (~> 2.1)
|
50
|
+
rspec (>= 2.14, < 4.0)
|
51
|
+
i18n (0.6.11)
|
51
52
|
json (1.8.1)
|
52
|
-
listen (2.
|
53
|
+
listen (2.7.9)
|
53
54
|
celluloid (>= 0.15.2)
|
54
55
|
rb-fsevent (>= 0.9.3)
|
55
56
|
rb-inotify (>= 0.9)
|
56
|
-
lumberjack (1.0.
|
57
|
+
lumberjack (1.0.9)
|
57
58
|
method_source (0.8.2)
|
58
|
-
mime-types (
|
59
|
+
mime-types (2.3)
|
59
60
|
mimemagic (0.2.1)
|
60
|
-
minitest (5.
|
61
|
-
multi_json (1.
|
61
|
+
minitest (5.4.0)
|
62
|
+
multi_json (1.10.1)
|
62
63
|
multipart-post (2.0.0)
|
64
|
+
netrc (0.7.7)
|
63
65
|
oauth (0.4.7)
|
64
|
-
parallel (1.
|
65
|
-
pry (0.
|
66
|
-
coderay (~> 1.0
|
67
|
-
method_source (~> 0.8)
|
66
|
+
parallel (1.2.0)
|
67
|
+
pry (0.10.0)
|
68
|
+
coderay (~> 1.1.0)
|
69
|
+
method_source (~> 0.8.1)
|
68
70
|
slop (~> 3.4)
|
69
|
-
rake (10.3.
|
70
|
-
rb-fsevent (0.9.
|
71
|
-
rb-inotify (0.9.
|
71
|
+
rake (10.3.2)
|
72
|
+
rb-fsevent (0.9.4)
|
73
|
+
rb-inotify (0.9.5)
|
72
74
|
ffi (>= 0.5.0)
|
73
|
-
rest-client (1.
|
74
|
-
mime-types (>= 1.16)
|
75
|
-
|
76
|
-
|
77
|
-
rspec-
|
78
|
-
rspec-
|
79
|
-
|
80
|
-
rspec-
|
81
|
-
|
82
|
-
rspec-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
75
|
+
rest-client (1.7.2)
|
76
|
+
mime-types (>= 1.16, < 3.0)
|
77
|
+
netrc (~> 0.7)
|
78
|
+
rspec (3.0.0)
|
79
|
+
rspec-core (~> 3.0.0)
|
80
|
+
rspec-expectations (~> 3.0.0)
|
81
|
+
rspec-mocks (~> 3.0.0)
|
82
|
+
rspec-core (3.0.3)
|
83
|
+
rspec-support (~> 3.0.0)
|
84
|
+
rspec-expectations (3.0.3)
|
85
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
86
|
+
rspec-support (~> 3.0.0)
|
87
|
+
rspec-its (1.0.1)
|
88
|
+
rspec-core (>= 2.99.0.beta1)
|
89
|
+
rspec-expectations (>= 2.99.0.beta1)
|
90
|
+
rspec-mocks (3.0.3)
|
91
|
+
rspec-support (~> 3.0.0)
|
92
|
+
rspec-support (3.0.3)
|
93
|
+
simple_oauth (0.2.0)
|
94
|
+
simplecov (0.9.0)
|
95
|
+
docile (~> 1.1.0)
|
96
|
+
multi_json
|
97
|
+
simplecov-html (~> 0.8.0)
|
98
|
+
simplecov-html (0.8.0)
|
99
|
+
slop (3.6.0)
|
100
|
+
term-ansicolor (1.3.0)
|
101
|
+
tins (~> 1.0)
|
102
|
+
thor (0.19.1)
|
103
|
+
thread_safe (0.3.4)
|
92
104
|
timers (1.1.0)
|
93
|
-
tins (
|
94
|
-
tzinfo (1.
|
105
|
+
tins (1.3.0)
|
106
|
+
tzinfo (1.2.2)
|
95
107
|
thread_safe (~> 0.1)
|
96
108
|
|
97
109
|
PLATFORMS
|
@@ -99,8 +111,8 @@ PLATFORMS
|
|
99
111
|
|
100
112
|
DEPENDENCIES
|
101
113
|
coveralls
|
102
|
-
debugger
|
103
114
|
guard-rspec
|
104
115
|
rspec
|
116
|
+
rspec-its
|
105
117
|
simplecov
|
106
118
|
xing_api_client!
|
data/README.md
CHANGED
@@ -40,6 +40,8 @@ client = XingApiClient.new(authorized_params[:access_token], authorized_params[:
|
|
40
40
|
puts client.request.get_users.inspect
|
41
41
|
```
|
42
42
|
|
43
|
+
[Here](https://github.com/ependichter/xing_api_client_example) you can find an minimal example with Sinatra using a callback URL.
|
44
|
+
|
43
45
|
## Before you start
|
44
46
|
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 .
|
45
47
|
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).
|
data/lib/xing_api_client.rb
CHANGED
@@ -3,6 +3,7 @@ require 'json'
|
|
3
3
|
require 'open-uri'
|
4
4
|
require 'yaml'
|
5
5
|
require 'ostruct'
|
6
|
+
require 'faraday_middleware'
|
6
7
|
require 'active_support/core_ext/hash/indifferent_access'
|
7
8
|
%w{ version config object call request}.each{ |name| require_relative "xing_api_client/#{name}"}
|
8
9
|
|
@@ -22,17 +23,28 @@ class XingApiClient
|
|
22
23
|
|
23
24
|
token = consumer.get_request_token(oauth_params)
|
24
25
|
|
25
|
-
|
26
|
+
warn "[DEPRECATION] returning ':request_token' is deprecated. Please use the Hash unter the key ':oauth' with the keys ':token' and ':secret' instead."
|
27
|
+
{ request_token: token, auth_url: token.authorize_url, oauth: { token: token.token , secret: token.secret} }
|
26
28
|
end
|
27
29
|
|
28
|
-
def self.authorize(
|
29
|
-
|
30
|
+
def self.authorize(token_or_hash, *args)
|
31
|
+
if token_or_hash.is_a?(OAuth::RequestToken)
|
32
|
+
warn "[DEPRECATION] calling '.authorize' with a OAuth::RequestToken is deprecated. Please use a Hash with the keys ':token',':secret' and ':verifier' instead."
|
33
|
+
|
34
|
+
token = token_or_hash
|
35
|
+
verifier = args.first
|
36
|
+
else
|
37
|
+
token = OAuth::RequestToken.new(consumer, token_or_hash[:token], token_or_hash[:secret])
|
38
|
+
verifier = token_or_hash[:verifier]
|
39
|
+
end
|
40
|
+
|
41
|
+
access_token = token.get_access_token(oauth_verifier: verifier)
|
30
42
|
|
31
43
|
{ access_token: access_token.token, secret: access_token.secret }
|
32
44
|
end
|
33
45
|
|
34
46
|
def request
|
35
|
-
Request.new(
|
47
|
+
Request.new(connection)
|
36
48
|
end
|
37
49
|
|
38
50
|
def self.consumer(options = {})
|
@@ -51,4 +63,20 @@ private
|
|
51
63
|
def consumer_token
|
52
64
|
OAuth::ConsumerToken.new(@consumer, @access_token, @secret)
|
53
65
|
end
|
66
|
+
|
67
|
+
def connection
|
68
|
+
Faraday.new(:url => config.host) do |faraday|
|
69
|
+
faraday.request :multipart
|
70
|
+
faraday.request :json
|
71
|
+
faraday.request(:oauth, {
|
72
|
+
consumer_key: config.consumer_key,
|
73
|
+
consumer_secret: config.consumer_secret,
|
74
|
+
token: @access_token,
|
75
|
+
token_secret: @secret
|
76
|
+
}
|
77
|
+
)
|
78
|
+
faraday.response :logger if config.debug
|
79
|
+
faraday.adapter Faraday.default_adapter
|
80
|
+
end
|
81
|
+
end
|
54
82
|
end
|
@@ -2,6 +2,12 @@ class XingApiClient
|
|
2
2
|
module Call
|
3
3
|
module Base
|
4
4
|
|
5
|
+
def direct(verb, url, params, options = {})
|
6
|
+
verb = "#{verb}_multipart" if options[:multipart]
|
7
|
+
|
8
|
+
handle_request(verb, url, params)
|
9
|
+
end
|
10
|
+
|
5
11
|
private
|
6
12
|
def request_loop(total, result, offset, requested_limit, max_limit_per_call = 100)
|
7
13
|
offset ||= 0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class XingApiClient
|
2
|
+
module Call
|
3
|
+
module UsersNetworkRecommendationsCall
|
4
|
+
def get_users_network_recommendations(options = {})
|
5
|
+
offset = options[:offset]
|
6
|
+
limit = options[:limit]
|
7
|
+
params = { user_id: "me", user_fields: options[:fields] }
|
8
|
+
params.merge!(since: options[:similar_user_id]) unless options[:similar_user_id].nil?
|
9
|
+
|
10
|
+
request = make_request!(:get, "v1/users/me/network/recommendations", params.merge(limit: (limit || 100), offset: offset), array_keys: "user_recommendations")
|
11
|
+
|
12
|
+
request["recommendations"].tap do |collection|
|
13
|
+
collection.define_singleton_method :total, -> { request["total"].to_i }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete_users_network_recommendations(id)
|
18
|
+
make_request!(:delete, "v1/users/me/network/recommendations/#{id}", {}, allowed_codes: 204)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -17,12 +17,12 @@ class XingApiClient
|
|
17
17
|
404 => ResourceNotFoundError
|
18
18
|
}
|
19
19
|
|
20
|
-
def initialize(
|
21
|
-
@
|
20
|
+
def initialize(connection)
|
21
|
+
@connection = connection
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
|
-
attr_reader :
|
25
|
+
attr_reader :connection
|
26
26
|
|
27
27
|
def map_user(data)
|
28
28
|
XingApiClient::Object::User.new data
|
@@ -31,12 +31,11 @@ class XingApiClient
|
|
31
31
|
def make_request!(verb, url, params = nil, options = {})
|
32
32
|
options = { array_keys: [], allowed_codes: [200] }.merge(options)
|
33
33
|
url = [config.host, url].join('/')
|
34
|
-
|
35
34
|
request_params = add_default_values(params)
|
36
35
|
|
37
36
|
result = handle_request(verb, url, request_params)
|
38
37
|
data = handle_result(result, options[:content_type])
|
39
|
-
handle_error!(result.
|
38
|
+
handle_error!(result.status, data, options[:allowed_codes])
|
40
39
|
|
41
40
|
Array(options[:array_keys]).each { |key| data = data[key] }
|
42
41
|
|
@@ -57,6 +56,8 @@ class XingApiClient
|
|
57
56
|
value.to_i
|
58
57
|
when :user_fields
|
59
58
|
value || XingApiClient::Object::User::AVAILABLE_FIELDS.join(',')
|
59
|
+
when :phone, :mobile_phone, :fax
|
60
|
+
value.is_a?(Array) ? value.join("|") : value
|
60
61
|
else
|
61
62
|
value
|
62
63
|
end
|
@@ -72,43 +73,24 @@ class XingApiClient
|
|
72
73
|
if multipart
|
73
74
|
handle_multipart_request(verb, url, params)
|
74
75
|
elsif verb == "get"
|
75
|
-
|
76
|
+
connection.send(verb, url + generate_url_params(params))
|
76
77
|
else
|
77
|
-
|
78
|
+
connection.send(verb, url, params)
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
81
82
|
# Not automatic tested right now... Oo
|
82
83
|
def handle_multipart_request(verb, url, params)
|
83
|
-
uri = URI.parse(url)
|
84
|
-
multipart_class = case verb.to_sym
|
85
|
-
when :post
|
86
|
-
Net::HTTP::Post::Multipart
|
87
|
-
when :put
|
88
|
-
Net::HTTP::Put::Multipart
|
89
|
-
else
|
90
|
-
raise XingApiClient::Error::UnknownHttpMethodError
|
91
|
-
end
|
92
84
|
multipart_key, file_path = params.delete(:multipart).to_a.flatten
|
93
85
|
mimetype = MimeMagic.by_path file_path
|
94
86
|
|
95
87
|
raise XingApiClient::Error::FileMIMETypeUnknownError if mimetype.nil?
|
96
88
|
|
97
|
-
|
98
|
-
|
99
|
-
request_response = nil
|
100
|
-
File.open(file_path) do |image|
|
101
|
-
request = multipart_class.new(uri.path, multipart_key => UploadIO.new(image, mimetype, file_name))
|
102
|
-
consumer_token.sign! request
|
103
|
-
request_response = Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
|
104
|
-
http.request(request)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
request_response
|
89
|
+
connection.send(verb, url, multipart_key => Faraday::UploadIO.new(file_path, mimetype))
|
108
90
|
end
|
109
91
|
|
110
92
|
def handle_result(result, content_type)
|
111
|
-
|
93
|
+
if not result.body.to_s.empty?
|
112
94
|
if content_type == 'text'
|
113
95
|
result.body
|
114
96
|
else
|
@@ -125,9 +107,10 @@ class XingApiClient
|
|
125
107
|
code = code.to_i
|
126
108
|
return if Array(allowed_codes).include?(code)
|
127
109
|
|
128
|
-
|
110
|
+
error_name = data.nil? ? code : data['error_name']
|
111
|
+
error_class = ERROR_CLASSES[error_name] || Error
|
129
112
|
|
130
|
-
raise error_class.new(code,
|
113
|
+
raise error_class.new(code, error_name, data)
|
131
114
|
end
|
132
115
|
end
|
133
116
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe XingApiClient::Call::UsersNetworkRecommendationsCall do
|
4
|
+
let(:call) { Object.new.tap{ |object| object.extend(XingApiClient::Call::UsersNetworkRecommendationsCall) } }
|
5
|
+
|
6
|
+
describe '#get_users_network_recommendations' do
|
7
|
+
context 'with no options' do
|
8
|
+
subject do
|
9
|
+
call.
|
10
|
+
should_receive(:make_request!).
|
11
|
+
with(:get, "v1/users/me/network/recommendations", {:user_id=>"me", :user_fields=>nil, :limit=>100, :offset=>nil}, {:array_keys=>"user_recommendations"}).
|
12
|
+
and_return({ "recommendations" => [], "total" => 0 })
|
13
|
+
|
14
|
+
call.get_users_network_recommendations()
|
15
|
+
end
|
16
|
+
|
17
|
+
its(:class) { should == Array }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with all options' do
|
21
|
+
subject do
|
22
|
+
call.
|
23
|
+
should_receive(:make_request!).
|
24
|
+
with(:get, "v1/users/me/network/recommendations", {:user_id=>"me", :user_fields=>nil, :since=>"123456_abcdef", :limit=>"99", :offset=>"30"}, {:array_keys=>"user_recommendations"}).
|
25
|
+
and_return({ "recommendations" => [], "total" => 0 })
|
26
|
+
|
27
|
+
call.get_users_network_recommendations(offset: '30', limit: '99', similar_user_id: '123456_abcdef',user_fields: [:id, :page_name])
|
28
|
+
end
|
29
|
+
|
30
|
+
its(:class) { should == Array }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#get_users_network_recommendations' do
|
35
|
+
subject do
|
36
|
+
call.
|
37
|
+
should_receive(:make_request!).
|
38
|
+
with(:delete, "v1/users/me/network/recommendations/some-123456_abcdef", {}, {:allowed_codes=>204}).
|
39
|
+
and_return(nil)
|
40
|
+
|
41
|
+
call.delete_users_network_recommendations('some-123456_abcdef')
|
42
|
+
end
|
43
|
+
|
44
|
+
its(:class) { should == NilClass }
|
45
|
+
end
|
46
|
+
end
|
@@ -27,7 +27,7 @@ describe XingApiClient::Object::User do
|
|
27
27
|
its(:web_profiles) { should == {} }
|
28
28
|
its(:instant_messaging_accounts) { should == {"skype"=>"username"} }
|
29
29
|
its(:professional_experience) { should_not be_empty }
|
30
|
-
its(:professional_experience) { subject.professional_experience.all?{ |e| e.kind_of?(XingApiClient::Object::Company) }.should
|
30
|
+
its(:professional_experience) { subject.professional_experience.all?{ |e| e.kind_of?(XingApiClient::Object::Company) }.should == true }
|
31
31
|
its(:photo_urls) { should == {"large"=>"https://x1.xingassets.com/img/users/3/5/1/238ddffce.13802856,9.140x185.jpg",
|
32
32
|
"maxi_thumb"=>"https://x1.xingassets.com/img/users/3/5/1/238ddffce.13802856,9.70x93.jpg",
|
33
33
|
"medium_thumb"=>"https://x1.xingassets.com/img/users/3/5/1/238ddffce.13802856,9.57x75.jpg",
|
@@ -27,7 +27,7 @@ describe XingApiClient::Object::User do
|
|
27
27
|
its(:web_profiles) { should == {} }
|
28
28
|
its(:instant_messaging_accounts) { should == {"skype"=>"username"} }
|
29
29
|
its(:professional_experience) { should_not be_empty }
|
30
|
-
its(:professional_experience) { subject.professional_experience.all?{ |e| e.kind_of?(XingApiClient::Object::Company) }.should
|
30
|
+
its(:professional_experience) { subject.professional_experience.all?{ |e| e.kind_of?(XingApiClient::Object::Company) }.should == true }
|
31
31
|
its(:photo_urls) { should == {"large"=>"https://x1.xingassets.com/img/users/3/5/1/238ddffce.13802856,9.140x185.jpg",
|
32
32
|
"maxi_thumb"=>"https://x1.xingassets.com/img/users/3/5/1/238ddffce.13802856,9.70x93.jpg",
|
33
33
|
"medium_thumb"=>"https://x1.xingassets.com/img/users/3/5/1/238ddffce.13802856,9.57x75.jpg",
|
@@ -2,12 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe XingApiClient::Request do
|
4
4
|
subject { XingApiClient::Request }
|
5
|
-
let(:instance){ subject.new(
|
6
|
-
let(:
|
5
|
+
let(:instance){ subject.new(connection) }
|
6
|
+
let(:connection) { double('connection') }
|
7
7
|
|
8
8
|
describe '.new' do
|
9
9
|
it 'sets the intsance variable access_token to the argument when it gets initialized' do
|
10
|
-
instance.instance_variable_get('@
|
10
|
+
instance.instance_variable_get('@connection').should == connection
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -44,7 +44,7 @@ describe XingApiClient::Request do
|
|
44
44
|
|
45
45
|
context 'other values' do
|
46
46
|
it 'returns the values untouched' do
|
47
|
-
test_thing =
|
47
|
+
test_thing = double('something')
|
48
48
|
instance.send(:add_default_values, other: test_thing ).should == { other: test_thing }
|
49
49
|
end
|
50
50
|
end
|
@@ -55,11 +55,11 @@ describe XingApiClient::Request do
|
|
55
55
|
params = { some_param: 'some_value' }
|
56
56
|
options = { array_keys: 'users', allowed_codes: 204, content_type: 'text' }
|
57
57
|
request_params = { other_param: 'some_value'}
|
58
|
-
result =
|
58
|
+
result = double('result', status: 204)
|
59
59
|
|
60
|
-
instance.
|
61
|
-
instance.
|
62
|
-
instance.
|
60
|
+
expect(instance).to receive(:add_default_values).with(params).and_return(request_params)
|
61
|
+
expect(instance).to receive(:handle_request).with(:get, 'https://api.xing.com/v1/something', request_params).and_return(result)
|
62
|
+
expect(instance).to receive(:handle_result).with(result, options[:content_type]).and_return('users' => 'some data')
|
63
63
|
|
64
64
|
instance.send(:make_request!, :get, 'v1/something', params, options).should == 'some data'
|
65
65
|
end
|
@@ -73,31 +73,31 @@ describe XingApiClient::Request do
|
|
73
73
|
let(:verb){ :get }
|
74
74
|
|
75
75
|
it 'adds the params to the url' do
|
76
|
-
|
76
|
+
connection.should_receive(:get).with("www.test.com?param1=1¶m2=2")
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
80
|
context 'post request' do
|
81
81
|
let(:verb){ :post }
|
82
82
|
|
83
|
-
it 'adds the params to the
|
84
|
-
|
83
|
+
it 'adds the params to the url' do
|
84
|
+
connection.should_receive(:post).with("www.test.com", {:param1=>"1", :param2=>"2"})
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
88
|
context 'put request' do
|
89
89
|
let(:verb){ :put }
|
90
90
|
|
91
|
-
it 'adds the params to the
|
92
|
-
|
91
|
+
it 'adds the params to the url' do
|
92
|
+
connection.should_receive(:put).with("www.test.com", {:param1=>"1", :param2=>"2"})
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
context 'delete request' do
|
97
97
|
let(:verb){ :delete }
|
98
98
|
|
99
|
-
it 'adds the params to the
|
100
|
-
|
99
|
+
it 'adds the params to the url' do
|
100
|
+
connection.should_receive(:delete).with("www.test.com", {:param1=>"1", :param2=>"2"})
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -123,7 +123,7 @@ describe XingApiClient::Request do
|
|
123
123
|
describe '#handle_result' do
|
124
124
|
|
125
125
|
context 'the result body is nil' do
|
126
|
-
let(:result){
|
126
|
+
let(:result){ double('result') }
|
127
127
|
let(:content_type){}
|
128
128
|
|
129
129
|
before{ result.should_receive(:body).and_return(nil) }
|
@@ -134,7 +134,7 @@ describe XingApiClient::Request do
|
|
134
134
|
end
|
135
135
|
|
136
136
|
context 'the result body is not nil' do
|
137
|
-
let(:result){
|
137
|
+
let(:result){ double('result') }
|
138
138
|
before{ result.stub(:body).and_return('{ "male": true }') }
|
139
139
|
|
140
140
|
context 'the content_type is == "text"' do
|
@@ -5,25 +5,44 @@ describe XingApiClient do
|
|
5
5
|
let(:instance){ subject.new('access_token_ABC123', 'secret_DEF456') }
|
6
6
|
|
7
7
|
describe '.request_params' do
|
8
|
-
let(:
|
8
|
+
let(:oauth_parameter_hash) { { token: 'request_token_ABC123', secret: 'secret_ABC123' } }
|
9
|
+
let(:token) { double('request_token', authorize_url: 'www.url.sample', token: oauth_parameter_hash[:token], secret: oauth_parameter_hash[:secret] ) }
|
9
10
|
before { subject.stub_chain(:consumer, :get_request_token).and_return(token) }
|
10
11
|
|
11
12
|
it 'returns a hash with a request token and a auth url' do
|
12
|
-
subject.request_params.should == { request_token: token, auth_url: 'www.url.sample'}
|
13
|
+
subject.request_params.should == { request_token: token, auth_url: 'www.url.sample', oauth: oauth_parameter_hash}
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
describe '.authorize' do
|
17
|
-
let(:request_token) { double('
|
18
|
-
let(:pin) { '1234' }
|
18
|
+
let(:request_token) { double('request token') }
|
19
19
|
let(:access_token) { double('access_token', token: 'access_token_ABC123', secret: 'secret_DEF456' ) }
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
context 'with a token an pin - depecated' do
|
22
|
+
let(:pin) { '1234' }
|
23
|
+
|
24
|
+
before do
|
25
|
+
request_token.should_receive(:is_a?).with(OAuth::RequestToken).and_return(true)
|
26
|
+
request_token.should_receive(:get_access_token).with(oauth_verifier: pin).and_return(access_token)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns a hash with a access token and a secret' do
|
30
|
+
subject.authorize(request_token, pin).should == { access_token: 'access_token_ABC123', secret: 'secret_DEF456'}
|
31
|
+
end
|
23
32
|
end
|
24
33
|
|
25
|
-
|
26
|
-
|
34
|
+
context 'with a hash' do
|
35
|
+
let(:oauth_parameter_hash) { { token: 'request_token_ABC123', secret: 'secret_ABC123', verifier: '1234' } }
|
36
|
+
let(:consumer) { double('consumer') }
|
37
|
+
before do
|
38
|
+
subject.should_receive(:consumer).and_return(consumer)
|
39
|
+
OAuth::RequestToken.should_receive(:new).with(consumer, oauth_parameter_hash[:token], oauth_parameter_hash[:secret]).and_return(request_token)
|
40
|
+
request_token.should_receive(:get_access_token).with(oauth_verifier: oauth_parameter_hash[:verifier]).and_return(access_token)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns a hash with a access token and a secret' do
|
44
|
+
subject.authorize(oauth_parameter_hash).should == { access_token: 'access_token_ABC123', secret: 'secret_DEF456'}
|
45
|
+
end
|
27
46
|
end
|
28
47
|
end
|
29
48
|
|
data/xing_api_client.gemspec
CHANGED
@@ -17,13 +17,16 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
19
|
spec.add_development_dependency "rspec"
|
20
|
+
spec.add_development_dependency "rspec-its"
|
20
21
|
spec.add_development_dependency "guard-rspec"
|
21
|
-
spec.
|
22
|
-
spec.add_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_dependency "bundler"
|
23
23
|
spec.add_dependency "rake"
|
24
24
|
spec.add_dependency "oauth"
|
25
25
|
spec.add_dependency "multipart-post"
|
26
26
|
spec.add_dependency "activesupport"
|
27
27
|
spec.add_dependency "parallel"
|
28
28
|
spec.add_dependency "mimemagic"
|
29
|
+
spec.add_dependency "faraday"
|
30
|
+
spec.add_dependency "faraday_middleware"
|
31
|
+
spec.add_dependency "simple_oauth"
|
29
32
|
end
|
metadata
CHANGED
@@ -1,153 +1,195 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xing_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Brendel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rspec-its
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: guard-rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: oauth
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: multipart-post
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: activesupport
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: parallel
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - '>='
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - '>='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: mimemagic
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: faraday
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: faraday_middleware
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: simple_oauth
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - '>='
|
144
186
|
- !ruby/object:Gem::Version
|
145
187
|
version: '0'
|
146
188
|
type: :runtime
|
147
189
|
prerelease: false
|
148
190
|
version_requirements: !ruby/object:Gem::Requirement
|
149
191
|
requirements:
|
150
|
-
- -
|
192
|
+
- - '>='
|
151
193
|
- !ruby/object:Gem::Version
|
152
194
|
version: '0'
|
153
195
|
description: Wrapper for the XING API
|
@@ -183,6 +225,7 @@ files:
|
|
183
225
|
- lib/xing_api_client/call/users_me_id_card_call.rb
|
184
226
|
- lib/xing_api_client/call/users_me_photo_call.rb
|
185
227
|
- lib/xing_api_client/call/users_network_paths_call.rb
|
228
|
+
- lib/xing_api_client/call/users_network_recommendations_call.rb
|
186
229
|
- lib/xing_api_client/call/users_profile_message_call.rb
|
187
230
|
- lib/xing_api_client/call/users_visits_call.rb
|
188
231
|
- lib/xing_api_client/config.rb
|
@@ -208,6 +251,7 @@ files:
|
|
208
251
|
- spec/xing_api_client/call/users_me_id_card_call_spec.rb
|
209
252
|
- spec/xing_api_client/call/users_me_photo_call_spec.rb
|
210
253
|
- spec/xing_api_client/call/users_network_paths_call_spec.rb
|
254
|
+
- spec/xing_api_client/call/users_network_recommendations_spec.rb
|
211
255
|
- spec/xing_api_client/call/users_profile_message_call_spec.rb
|
212
256
|
- spec/xing_api_client/call/users_visits_call_spec.rb
|
213
257
|
- spec/xing_api_client/config_spec.rb
|
@@ -229,17 +273,17 @@ require_paths:
|
|
229
273
|
- lib
|
230
274
|
required_ruby_version: !ruby/object:Gem::Requirement
|
231
275
|
requirements:
|
232
|
-
- -
|
276
|
+
- - '>='
|
233
277
|
- !ruby/object:Gem::Version
|
234
278
|
version: '0'
|
235
279
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
280
|
requirements:
|
237
|
-
- -
|
281
|
+
- - '>='
|
238
282
|
- !ruby/object:Gem::Version
|
239
283
|
version: '0'
|
240
284
|
requirements: []
|
241
285
|
rubyforge_project:
|
242
|
-
rubygems_version: 2.
|
286
|
+
rubygems_version: 2.0.14
|
243
287
|
signing_key:
|
244
288
|
specification_version: 4
|
245
289
|
summary: An easy way to access the XING API
|
@@ -256,6 +300,7 @@ test_files:
|
|
256
300
|
- spec/xing_api_client/call/users_me_id_card_call_spec.rb
|
257
301
|
- spec/xing_api_client/call/users_me_photo_call_spec.rb
|
258
302
|
- spec/xing_api_client/call/users_network_paths_call_spec.rb
|
303
|
+
- spec/xing_api_client/call/users_network_recommendations_spec.rb
|
259
304
|
- spec/xing_api_client/call/users_profile_message_call_spec.rb
|
260
305
|
- spec/xing_api_client/call/users_visits_call_spec.rb
|
261
306
|
- spec/xing_api_client/config_spec.rb
|