xing_api_client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +25 -13
- data/lib/xing_api_client/call/users_legal_information_call.rb +9 -0
- data/lib/xing_api_client/call/users_me_photo_call.rb +13 -0
- data/lib/xing_api_client/request/error.rb +9 -6
- data/lib/xing_api_client/request.rb +37 -2
- data/lib/xing_api_client/version.rb +1 -1
- data/spec/xing_api_client/call/users_legal_information_call_spec.rb +35 -0
- data/spec/xing_api_client/call/users_me_photo_call_spec.rb +33 -0
- data/spec/xing_api_client/request_spec.rb +34 -2
- data/xing_api_client.gemspec +3 -0
- metadata +49 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2E4ZTQ2ZTc0YmVjOGQxNWYzNWJhMmVhYmI1MGMzYzZkMzZlMzdhNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmFmNjJlOThlZWM3YjA1M2ZmYzNlMzk1ZWZjYTcyMjFlOGYxNzdkYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGNkOWY0OWEzZmIyODEwODNkZjQ3YTVlMDczY2NlNzhlNzYwM2ZjNzBlNDI2
|
10
|
+
ZGJhMzhhNjQ1YzhmMDQ2ZDhhZmFjMjE3ZjUxNWVkOGNmOGNmZDI4ZGIzMjI3
|
11
|
+
NGQ5M2Y3YmMyMTBmYzgwMDE2MzY4NmY3MjVkOGI2NTE4NDlhYTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjYwMTFmOGMyZTJmNGE0MDQ4Yjg2MjQ4NmI3ZDE2OGNiZjE3ZmQxYmI3MDQz
|
14
|
+
NTFiOTE3MDAzNDRiN2UyNTI2NDI5NWJhYTBiNWI3YWM3YWU5ZDQwNzczNTIw
|
15
|
+
YTE3OTIwYmM0NTE0ZjQ1YTU3MmQ4NzI2NzhjNWI4NjlhNzc2MmE=
|
data/Gemfile.lock
CHANGED
@@ -4,6 +4,8 @@ PATH
|
|
4
4
|
xing_api_client (0.0.2)
|
5
5
|
activesupport
|
6
6
|
bundler (~> 1.3)
|
7
|
+
mimemagic
|
8
|
+
multipart-post
|
7
9
|
oauth
|
8
10
|
parallel
|
9
11
|
rake
|
@@ -11,22 +13,28 @@ PATH
|
|
11
13
|
GEM
|
12
14
|
remote: https://rubygems.org/
|
13
15
|
specs:
|
14
|
-
activesupport (4.
|
15
|
-
i18n (~> 0.6, >= 0.6.
|
16
|
-
|
17
|
-
|
16
|
+
activesupport (4.1.0)
|
17
|
+
i18n (~> 0.6, >= 0.6.9)
|
18
|
+
json (~> 1.7, >= 1.7.7)
|
19
|
+
minitest (~> 5.1)
|
18
20
|
thread_safe (~> 0.1)
|
19
|
-
tzinfo (~>
|
20
|
-
atomic (1.1.14)
|
21
|
+
tzinfo (~> 1.1)
|
21
22
|
celluloid (0.15.2)
|
22
23
|
timers (~> 1.1.0)
|
23
24
|
coderay (1.0.9)
|
25
|
+
columnize (0.8.9)
|
24
26
|
coveralls (0.7.0)
|
25
27
|
multi_json (~> 1.3)
|
26
28
|
rest-client
|
27
29
|
simplecov (>= 0.7)
|
28
30
|
term-ansicolor
|
29
31
|
thor
|
32
|
+
debugger (1.6.6)
|
33
|
+
columnize (>= 0.3.1)
|
34
|
+
debugger-linecache (~> 1.2.0)
|
35
|
+
debugger-ruby_core_source (~> 1.3.2)
|
36
|
+
debugger-linecache (1.2.0)
|
37
|
+
debugger-ruby_core_source (1.3.2)
|
30
38
|
diff-lcs (1.2.4)
|
31
39
|
ffi (1.9.0)
|
32
40
|
formatador (0.2.4)
|
@@ -39,7 +47,8 @@ GEM
|
|
39
47
|
guard-rspec (4.0.3)
|
40
48
|
guard (>= 2.1.1)
|
41
49
|
rspec (~> 2.14)
|
42
|
-
i18n (0.6.
|
50
|
+
i18n (0.6.9)
|
51
|
+
json (1.8.1)
|
43
52
|
listen (2.1.1)
|
44
53
|
celluloid (>= 0.15.2)
|
45
54
|
rb-fsevent (>= 0.9.3)
|
@@ -47,15 +56,17 @@ GEM
|
|
47
56
|
lumberjack (1.0.4)
|
48
57
|
method_source (0.8.2)
|
49
58
|
mime-types (1.25)
|
50
|
-
|
59
|
+
mimemagic (0.2.1)
|
60
|
+
minitest (5.3.3)
|
51
61
|
multi_json (1.8.2)
|
62
|
+
multipart-post (2.0.0)
|
52
63
|
oauth (0.4.7)
|
53
|
-
parallel (0.
|
64
|
+
parallel (1.0.0)
|
54
65
|
pry (0.9.12.2)
|
55
66
|
coderay (~> 1.0.5)
|
56
67
|
method_source (~> 0.8)
|
57
68
|
slop (~> 3.4)
|
58
|
-
rake (10.1
|
69
|
+
rake (10.3.1)
|
59
70
|
rb-fsevent (0.9.3)
|
60
71
|
rb-inotify (0.9.2)
|
61
72
|
ffi (>= 0.5.0)
|
@@ -77,17 +88,18 @@ GEM
|
|
77
88
|
term-ansicolor (1.2.2)
|
78
89
|
tins (~> 0.8)
|
79
90
|
thor (0.18.1)
|
80
|
-
thread_safe (0.
|
81
|
-
atomic
|
91
|
+
thread_safe (0.3.3)
|
82
92
|
timers (1.1.0)
|
83
93
|
tins (0.12.0)
|
84
|
-
tzinfo (
|
94
|
+
tzinfo (1.1.0)
|
95
|
+
thread_safe (~> 0.1)
|
85
96
|
|
86
97
|
PLATFORMS
|
87
98
|
ruby
|
88
99
|
|
89
100
|
DEPENDENCIES
|
90
101
|
coveralls
|
102
|
+
debugger
|
91
103
|
guard-rspec
|
92
104
|
rspec
|
93
105
|
simplecov
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class XingApiClient
|
2
|
+
module Call
|
3
|
+
module UsersMePhotoCall
|
4
|
+
def put_users_me_photo(photo_path)
|
5
|
+
make_request!(:put_multipart, "v1/users/me/photo", {multipart: { photo: photo_path }}, allowed_codes: 204)
|
6
|
+
end
|
7
|
+
|
8
|
+
def delete_users_me_photo
|
9
|
+
make_request!(:delete, "v1/users/me/photo", {}, allowed_codes: 204)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
class XingApiClient
|
2
2
|
class Error < StandardError; end
|
3
|
+
class UnknownHttpMethodError < Error; end
|
4
|
+
class FileMIMETypeUnknownError < Error; end
|
3
5
|
|
4
6
|
class Request
|
5
7
|
class Error < XingApiClient::Error
|
6
8
|
attr_accessor :code, :api_name, :response
|
7
9
|
|
8
|
-
def initialize(code, api_name, response)
|
10
|
+
def initialize(code = nil, api_name = nil, response = nil)
|
9
11
|
@code = code
|
10
12
|
@api_name = api_name
|
11
13
|
@response = response
|
@@ -16,10 +18,11 @@ class XingApiClient
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
19
|
-
class
|
20
|
-
class
|
21
|
-
class
|
22
|
-
class
|
23
|
-
class
|
21
|
+
class UnknownResponseContentTypeError < Error; end
|
22
|
+
class InvalidParametersError < Error; end
|
23
|
+
class InvalidOauthTokenError < Error; end
|
24
|
+
class ThrottlingError < Error; end
|
25
|
+
class ResourceNotFoundError < Error; end
|
26
|
+
class AccessDeniedError < Error; end
|
24
27
|
end
|
25
28
|
end
|
@@ -2,6 +2,9 @@ class XingApiClient
|
|
2
2
|
class Request
|
3
3
|
require_relative 'request/error'
|
4
4
|
require 'parallel'
|
5
|
+
require 'net/http/post/multipart'
|
6
|
+
require 'pathname'
|
7
|
+
require 'mimemagic'
|
5
8
|
include Config
|
6
9
|
include XingApiClient::Call
|
7
10
|
|
@@ -33,7 +36,6 @@ class XingApiClient
|
|
33
36
|
|
34
37
|
result = handle_request(verb, url, request_params)
|
35
38
|
data = handle_result(result, options[:content_type])
|
36
|
-
|
37
39
|
handle_error!(result.code, data, options[:allowed_codes])
|
38
40
|
|
39
41
|
Array(options[:array_keys]).each { |key| data = data[key] }
|
@@ -65,13 +67,46 @@ class XingApiClient
|
|
65
67
|
end
|
66
68
|
|
67
69
|
def handle_request(verb, url, params)
|
68
|
-
|
70
|
+
verb, multipart = verb.to_s.split('_')
|
71
|
+
|
72
|
+
if multipart
|
73
|
+
handle_multipart_request(verb, url, params)
|
74
|
+
elsif verb == "get"
|
69
75
|
consumer_token.request(verb, url + generate_url_params(params))
|
70
76
|
else
|
71
77
|
consumer_token.request(verb, url, params)
|
72
78
|
end
|
73
79
|
end
|
74
80
|
|
81
|
+
# Not automatic tested right now... Oo
|
82
|
+
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
|
+
multipart_key, file_path = params.delete(:multipart).to_a.flatten
|
93
|
+
mimetype = MimeMagic.by_path file_path
|
94
|
+
|
95
|
+
raise XingApiClient::Error::FileMIMETypeUnknownError if mimetype.nil?
|
96
|
+
|
97
|
+
file_name = Pathname.new file_path
|
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
|
108
|
+
end
|
109
|
+
|
75
110
|
def handle_result(result, content_type)
|
76
111
|
unless result.body.nil?
|
77
112
|
if content_type == 'text'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe XingApiClient::Call::UsersLegalInformationCall do
|
4
|
+
let(:call) { Object.new.tap{ |object| object.extend(XingApiClient::Call::UsersLegalInformationCall) } }
|
5
|
+
|
6
|
+
describe '#get_users_legal_information' do
|
7
|
+
context "with no options" do
|
8
|
+
subject do
|
9
|
+
call.
|
10
|
+
should_receive(:make_request!).
|
11
|
+
with(:get, "v1/users/me/legal_information", {}, {:array_keys=>["legal_information"]}).
|
12
|
+
and_return({"content" => nil})
|
13
|
+
|
14
|
+
call.get_users_legal_information()
|
15
|
+
end
|
16
|
+
|
17
|
+
its(:class) { should == Hash }
|
18
|
+
its(:keys) { should == ['content'] }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with all options" do
|
22
|
+
subject do
|
23
|
+
call.
|
24
|
+
should_receive(:make_request!).
|
25
|
+
with(:get, "v1/users/1_abcdef/legal_information", {}, {:array_keys=>["legal_information"]}).
|
26
|
+
and_return({"content" => nil})
|
27
|
+
|
28
|
+
call.get_users_legal_information('1_abcdef')
|
29
|
+
end
|
30
|
+
|
31
|
+
its(:class) { should == Hash }
|
32
|
+
its(:keys) { should == ['content'] }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe XingApiClient::Call::UsersMePhotoCall do
|
4
|
+
let(:call) { Object.new.tap{ |object| object.extend(XingApiClient::Call::UsersMePhotoCall) } }
|
5
|
+
|
6
|
+
describe '#put_users_me_photo' do
|
7
|
+
subject do
|
8
|
+
call.
|
9
|
+
should_receive(:make_request!).
|
10
|
+
with(:put_multipart, "v1/users/me/photo", {multipart: {photo: "/path/to/file.jpg"}}, allowed_codes: 204).
|
11
|
+
and_return({})
|
12
|
+
|
13
|
+
call.put_users_me_photo("/path/to/file.jpg")
|
14
|
+
end
|
15
|
+
|
16
|
+
its(:class) { should == Hash }
|
17
|
+
its(:empty?) { should == true }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#delete_users_me_photo' do
|
21
|
+
subject do
|
22
|
+
call.
|
23
|
+
should_receive(:make_request!).
|
24
|
+
with(:delete, "v1/users/me/photo", {}, allowed_codes: 204).
|
25
|
+
and_return({})
|
26
|
+
|
27
|
+
call.delete_users_me_photo()
|
28
|
+
end
|
29
|
+
|
30
|
+
its(:class) { should == Hash }
|
31
|
+
its(:empty?) { should == true }
|
32
|
+
end
|
33
|
+
end
|
@@ -73,7 +73,7 @@ describe XingApiClient::Request do
|
|
73
73
|
let(:verb){ :get }
|
74
74
|
|
75
75
|
it 'adds the params to the url' do
|
76
|
-
consumer_token_object.should_receive(:request).with(
|
76
|
+
consumer_token_object.should_receive(:request).with("get", "www.test.com?param1=1¶m2=2")
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -81,7 +81,39 @@ describe XingApiClient::Request do
|
|
81
81
|
let(:verb){ :post }
|
82
82
|
|
83
83
|
it 'adds the params to the body' do
|
84
|
-
consumer_token_object.should_receive(:request).with(
|
84
|
+
consumer_token_object.should_receive(:request).with("post", "www.test.com", {:param1=>"1", :param2=>"2"})
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'put request' do
|
89
|
+
let(:verb){ :put }
|
90
|
+
|
91
|
+
it 'adds the params to the body' do
|
92
|
+
consumer_token_object.should_receive(:request).with("put", "www.test.com", {:param1=>"1", :param2=>"2"})
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'delete request' do
|
97
|
+
let(:verb){ :delete }
|
98
|
+
|
99
|
+
it 'adds the params to the body' do
|
100
|
+
consumer_token_object.should_receive(:request).with("delete", "www.test.com", {:param1=>"1", :param2=>"2"})
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'post multipart request' do
|
105
|
+
let(:verb){ :post_multipart }
|
106
|
+
|
107
|
+
it 'adds the params to the body' do
|
108
|
+
instance.should_receive(:handle_multipart_request).with("post", "www.test.com", {:param1=>"1", :param2=>"2"})
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'put multipart request' do
|
113
|
+
let(:verb){ :put_multipart }
|
114
|
+
|
115
|
+
it 'adds the params to the body' do
|
116
|
+
instance.should_receive(:handle_multipart_request).with("put", "www.test.com", {:param1=>"1", :param2=>"2"})
|
85
117
|
end
|
86
118
|
end
|
87
119
|
|
data/xing_api_client.gemspec
CHANGED
@@ -18,9 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.add_development_dependency "rspec"
|
20
20
|
spec.add_development_dependency "guard-rspec"
|
21
|
+
spec.add_development_dependency "debugger"
|
21
22
|
spec.add_dependency "bundler", "~> 1.3"
|
22
23
|
spec.add_dependency "rake"
|
23
24
|
spec.add_dependency "oauth"
|
25
|
+
spec.add_dependency "multipart-post"
|
24
26
|
spec.add_dependency "activesupport"
|
25
27
|
spec.add_dependency "parallel"
|
28
|
+
spec.add_dependency "mimemagic"
|
26
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Brendel
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: debugger
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - ! '>='
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: multipart-post
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
112
|
name: activesupport
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +136,20 @@ dependencies:
|
|
108
136
|
- - ! '>='
|
109
137
|
- !ruby/object:Gem::Version
|
110
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: mimemagic
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
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'
|
111
153
|
description: Wrapper for the XING API
|
112
154
|
email:
|
113
155
|
- ependichter@gmail.com
|
@@ -137,7 +179,9 @@ files:
|
|
137
179
|
- lib/xing_api_client/call/users_contacts_shared_call.rb
|
138
180
|
- lib/xing_api_client/call/users_contacts_tags_call.rb
|
139
181
|
- lib/xing_api_client/call/users_find_by_emails_call.rb
|
182
|
+
- lib/xing_api_client/call/users_legal_information_call.rb
|
140
183
|
- lib/xing_api_client/call/users_me_id_card_call.rb
|
184
|
+
- lib/xing_api_client/call/users_me_photo_call.rb
|
141
185
|
- lib/xing_api_client/call/users_network_paths_call.rb
|
142
186
|
- lib/xing_api_client/call/users_profile_message_call.rb
|
143
187
|
- lib/xing_api_client/call/users_visits_call.rb
|
@@ -160,7 +204,9 @@ files:
|
|
160
204
|
- spec/xing_api_client/call/users_contacts_shared_call_spec.rb
|
161
205
|
- spec/xing_api_client/call/users_contacts_tags_call_spec.rb
|
162
206
|
- spec/xing_api_client/call/users_find_by_emails_call_spec.rb
|
207
|
+
- spec/xing_api_client/call/users_legal_information_call_spec.rb
|
163
208
|
- spec/xing_api_client/call/users_me_id_card_call_spec.rb
|
209
|
+
- spec/xing_api_client/call/users_me_photo_call_spec.rb
|
164
210
|
- spec/xing_api_client/call/users_network_paths_call_spec.rb
|
165
211
|
- spec/xing_api_client/call/users_profile_message_call_spec.rb
|
166
212
|
- spec/xing_api_client/call/users_visits_call_spec.rb
|
@@ -206,7 +252,9 @@ test_files:
|
|
206
252
|
- spec/xing_api_client/call/users_contacts_shared_call_spec.rb
|
207
253
|
- spec/xing_api_client/call/users_contacts_tags_call_spec.rb
|
208
254
|
- spec/xing_api_client/call/users_find_by_emails_call_spec.rb
|
255
|
+
- spec/xing_api_client/call/users_legal_information_call_spec.rb
|
209
256
|
- spec/xing_api_client/call/users_me_id_card_call_spec.rb
|
257
|
+
- spec/xing_api_client/call/users_me_photo_call_spec.rb
|
210
258
|
- spec/xing_api_client/call/users_network_paths_call_spec.rb
|
211
259
|
- spec/xing_api_client/call/users_profile_message_call_spec.rb
|
212
260
|
- spec/xing_api_client/call/users_visits_call_spec.rb
|