xing_api_client 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,130 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Call::UsersContactRequestsCall do
4
+ let(:call) { Object.new.tap{ |object| object.extend(XingApiClient::Call::UsersContactRequestsCall) } }
5
+
6
+ describe '#get_users_contact_requests' do
7
+ context 'with no options' do
8
+ subject do
9
+ call.
10
+ should_receive(:make_request!).
11
+ with(:get, "v1/users/me/contact_requests", {:limit=>100, :offset=>0, :user_fields=>nil}, {:array_keys=>["contact_requests"]}).
12
+ and_return([{"id" => 1}])
13
+
14
+ call.get_users_contact_requests()
15
+ end
16
+
17
+ its(:size) { should == 1 }
18
+ end
19
+
20
+ context 'with all options' do
21
+ subject do
22
+ call.
23
+ should_receive(:make_request!).
24
+ with(:get, "v1/users/:user_id/contact_requests", {:limit=>30, :offset=>5, :user_fields=>["id", "display_name"]}, {:array_keys=>["contact_requests"]}).
25
+ and_return([{"id" => 1}])
26
+
27
+ call.get_users_contact_requests(id: ':user_id', offset: 5, limit: 30, fields: ['id', 'display_name'])
28
+ end
29
+
30
+ its(:size) { should == 1 }
31
+ end
32
+ end
33
+
34
+ describe '#delete_users_contact_requests' do
35
+ context 'with no options' do
36
+ subject do
37
+ call.
38
+ should_receive(:make_request!).
39
+ with(:delete, "v1/users/me/contact_requests/:recipient_id", {}, {:allowed_codes=>204}).
40
+ and_return(nil)
41
+
42
+ call.delete_users_contact_requests(':recipient_id')
43
+ end
44
+
45
+ its(:class) { should == NilClass }
46
+ end
47
+
48
+ context 'with all options' do
49
+ subject do
50
+ call.
51
+ should_receive(:make_request!).
52
+ with(:delete, "v1/users/:user_id/contact_requests/:recipient_id", {}, {:allowed_codes=>204}).
53
+ and_return(nil)
54
+
55
+ call.delete_users_contact_requests(':recipient_id', id: ':user_id')
56
+ end
57
+
58
+ its(:class) { should == NilClass }
59
+ end
60
+ end
61
+
62
+ describe '#post_users_contact_requests' do
63
+ subject do
64
+ call.
65
+ should_receive(:make_request!).
66
+ with(:post, "v1/users/:recipient_id/contact_requests", {:message=>"message"}, {:content_type=>"text", :allowed_codes=>201}).
67
+ and_return(nil)
68
+
69
+ call.post_users_contact_requests(':recipient_id', 'message')
70
+ end
71
+
72
+ its(:class) { should == NilClass }
73
+ end
74
+
75
+ describe '#put_users_contact_requests_accept' do
76
+ context 'with no options' do
77
+ subject do
78
+ call.
79
+ should_receive(:make_request!).
80
+ with(:put, "v1/users/me/contact_requests/:recipient_id/accept", {}, {:allowed_codes=>204}).
81
+ and_return(nil)
82
+
83
+ call.put_users_contact_requests_accept(':recipient_id')
84
+ end
85
+
86
+ its(:class) { should == NilClass }
87
+ end
88
+
89
+ context 'with all options' do
90
+ subject do
91
+ call.
92
+ should_receive(:make_request!).
93
+ with(:put, "v1/users/:user_id/contact_requests/:recipient_id/accept", {}, {:allowed_codes=>204}).
94
+ and_return(nil)
95
+
96
+ call.put_users_contact_requests_accept(':recipient_id', id: ':user_id')
97
+ end
98
+
99
+ its(:class) { should == NilClass }
100
+ end
101
+ end
102
+
103
+ describe '#get_users_contact_requests_sent' do
104
+ context 'with no options' do
105
+ subject do
106
+ call.
107
+ should_receive(:make_request!).
108
+ with(:get, "v1/users/me/contact_requests/sent", {}, {:array_keys=>"contact_requests"}).
109
+ and_return(nil)
110
+
111
+ call.get_users_contact_requests_sent()
112
+ end
113
+
114
+ its(:class) { should == NilClass }
115
+ end
116
+
117
+ context 'with all options' do
118
+ subject do
119
+ call.
120
+ should_receive(:make_request!).
121
+ with(:get, "v1/users/:user_id/contact_requests/sent", {}, {:array_keys=>"contact_requests"}).
122
+ and_return(nil)
123
+
124
+ call.get_users_contact_requests_sent(id: ':user_id', offset: 5, limit: 30)
125
+ end
126
+
127
+ its(:class) { should == NilClass }
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Call::UsersContactsCall do
4
+ let(:call) { Object.new.tap{ |object| object.extend(XingApiClient::Call::UsersContactsCall) } }
5
+
6
+ describe '#get_users_contacts' do
7
+ context 'with no options' do
8
+ subject do
9
+ call.
10
+ should_receive(:make_request!).
11
+ with(:get, "v1/users/me/contacts", {:limit=>100, :offset=>nil, :user_fields=>nil}, {:array_keys=>"contacts"}).
12
+ and_return("users" => [{'id' => 1}], "total" => '242')
13
+ call.
14
+ should_receive(:make_request!).
15
+ with(:get, "v1/users/me/contacts", {:limit=>100, :offset=>100, :user_fields=>nil}, {:array_keys=>["contacts", "users"]}).
16
+ and_return([{'id' => 2}])
17
+ call.
18
+ should_receive(:make_request!).
19
+ with(:get, "v1/users/me/contacts", {:limit=>100, :offset=>200, :user_fields=>nil}, {:array_keys=>["contacts", "users"]}).
20
+ and_return([{'id' => 3}])
21
+
22
+ call.get_users_contacts()
23
+ end
24
+
25
+ its(:class) { should == Array }
26
+ its(:size) { should == 3 }
27
+ its(:total) { should == 242 }
28
+ end
29
+
30
+ context 'with all options' do
31
+ subject do
32
+ call.
33
+ should_receive(:make_request!).
34
+ with(:get, "v1/users/:user_id/contacts", {:limit=>20, :offset=>5, :user_fields=>[:id, :page_name]}, {:array_keys=>"contacts"}).
35
+ and_return("users" => [{'id' => 1}], "total" => '242')
36
+
37
+ call.get_users_contacts(id: ':user_id', offset: 5 ,limit: 20, fields: [:id, :page_name])
38
+ end
39
+
40
+ its(:class) { should == Array }
41
+ its(:size) { should == 1 }
42
+ its(:total) { should == 242 }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Call::UsersContactsSharedCall do
4
+ let(:call) { Object.new.tap{ |object| object.extend(XingApiClient::Call::UsersContactsSharedCall) } }
5
+
6
+ describe '#get_users_contacts_shared' do
7
+ context 'with no options' do
8
+ subject do
9
+ call.
10
+ should_receive(:make_request!).
11
+ with(:get, "v1/users/:other_user_id/contacts/shared", {:user_fields=>nil, :limit=>100, :offset=>nil}, {:array_keys=>"shared_contacts"}).
12
+ and_return("users" => [{'id' => 1}], "total" => '242')
13
+ call.
14
+ should_receive(:make_request!).
15
+ with(:get, "v1/users/:other_user_id/contacts/shared", {:user_fields=>nil, :limit=>100, :offset=>100}, {:array_keys=>["shared_contacts", "users"]}).
16
+ and_return([{'id' => 2}])
17
+ call.
18
+ should_receive(:make_request!).
19
+ with(:get, "v1/users/:other_user_id/contacts/shared", {:user_fields=>nil, :limit=>100, :offset=>200}, {:array_keys=>["shared_contacts", "users"]}).
20
+ and_return([{'id' => 3}])
21
+
22
+ call.get_users_contacts_shared(':other_user_id')
23
+ end
24
+
25
+ its(:class) { should == Array }
26
+ its(:size) { should == 3 }
27
+ its(:total) { should == 242 }
28
+ end
29
+
30
+ context 'with all options' do
31
+ subject do
32
+ call.
33
+ should_receive(:make_request!).
34
+ with(:get, "v1/users/:other_user_id/contacts/shared", {:user_fields=>[:id, :page_name], :limit=>20, :offset=>5}, {:array_keys=>"shared_contacts"}).
35
+ and_return("users" => [{'id' => 1}], "total" => '242')
36
+
37
+ call.get_users_contacts_shared(':other_user_id', id: ':user_id', offset: 5 ,limit: 20, fields: [:id, :page_name])
38
+ end
39
+
40
+ its(:class) { should == Array }
41
+ its(:size) { should == 1 }
42
+ its(:total) { should == 242 }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Call::UsersContactsTagsCall do
4
+ let(:call) { Object.new.tap{ |object| object.extend(XingApiClient::Call::UsersContactsTagsCall) } }
5
+
6
+ describe '#get_users_contacts_tags' do
7
+ subject do
8
+ call.
9
+ should_receive(:make_request!).
10
+ with(:get, "v1/users/me/contacts/:contact_id/tags", {}, {:array_keys=>"tags"}).
11
+ and_return("total" => 242, "items" => [{"tag" => 1},{"tag" => 2}])
12
+
13
+ call.get_users_contacts_tags(':contact_id')
14
+ end
15
+
16
+ its(:class) { should == Array }
17
+ its(:size) { should == 2 }
18
+ its(:total) { should == 242 }
19
+ end
20
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Call::UsersFindByEmailsCall do
4
+ let(:call) { Object.new.tap{ |object| object.extend(XingApiClient::Call::UsersFindByEmailsCall) } }
5
+
6
+ describe '#get_users_find_by_emails' do
7
+ context 'with no options' do
8
+ subject do
9
+ call.
10
+ should_receive(:make_request!).
11
+ with(:get, "v1/users/find_by_emails", {:emails=>"email@host.de", :user_fields=>nil}, {:array_keys=>["results"]}).
12
+ and_return("total" => 202, "items" => [{"id" => 1},{"id" => 2}])
13
+
14
+ call.get_users_find_by_emails('email@host.de')
15
+ end
16
+
17
+ its(:class) { should == Array }
18
+ its(:size) { should == 2 }
19
+ its(:total) { should == 202 }
20
+ end
21
+
22
+ context 'with all options' do
23
+ subject do
24
+ call.
25
+ should_receive(:make_request!).
26
+ with(:get, "v1/users/find_by_emails", {:emails=>"email@host.de", :user_fields=>[:id, :page_name]}, {:array_keys=>["results"]}).
27
+ and_return("total" => 202, "items" => [{"id" => 1},{"id" => 2}])
28
+
29
+ call.get_users_find_by_emails('email@host.de', fields: [:id, :page_name])
30
+ end
31
+
32
+ its(:class) { should == Array }
33
+ its(:size) { should == 2 }
34
+ its(:total) { should == 202 }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Call::UsersMeIdCardCall do
4
+ let(:call) { Object.new.tap{ |object| object.extend(XingApiClient::Call::UsersMeIdCardCall) } }
5
+
6
+ describe '#get_users_me_id_card' do
7
+ subject do
8
+ call.
9
+ should_receive(:make_request!).
10
+ with(:get, "v1/users/me/id_card", {}, {:array_keys=>["id_card"]}).
11
+ and_return({"id" => 1})
12
+
13
+ call.get_users_me_id_card()
14
+ end
15
+
16
+ its(:class) { should == Hash }
17
+ its(:keys) { should == ['id'] }
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Call::UsersNetworkPathsCall do
4
+ let(:call) { Object.new.tap{ |object| object.extend(XingApiClient::Call::UsersNetworkPathsCall) } }
5
+
6
+ describe '#get_users_network_paths' do
7
+ context 'with no options' do
8
+ subject do
9
+ call.
10
+ should_receive(:make_request!).
11
+ with(:get, "v1/users/me/network/:other_user_id/paths", {}, {:array_keys=>["contact_paths"]}).
12
+ and_return({"paths" => [], "distance" => 2, "total" => '242'})
13
+
14
+ call.get_users_network_paths(':other_user_id')
15
+ end
16
+
17
+ its(:class) { should == Array }
18
+ its(:distance) { should == 2 }
19
+ its(:total) { should == 242 }
20
+ end
21
+
22
+ context 'with all options' do
23
+ subject do
24
+ call.
25
+ should_receive(:make_request!).
26
+ with(:get, "v1/users/:user_id/network/:other_user_id/paths", {}, {:array_keys=>["contact_paths"]}).
27
+ and_return({"paths" => [], "distance" => 2, "total" => '242'})
28
+
29
+ call.get_users_network_paths(':other_user_id', id: ':user_id')
30
+ end
31
+
32
+ its(:class) { should == Array }
33
+ its(:distance) { should == 2 }
34
+ its(:total) { should == 242 }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Call::UsersProfileMessageCall do
4
+ let(:call) { Object.new.tap{ |object| object.extend(XingApiClient::Call::UsersProfileMessageCall) } }
5
+
6
+ describe '#get_users_profile_message' do
7
+ context 'with no options' do
8
+ subject do
9
+ call.
10
+ should_receive(:make_request!).
11
+ with(:get, "v1/users/me/profile_message", {}, {:array_keys=>["profile_message"]}).
12
+ and_return("message" => nil)
13
+
14
+ call.get_users_profile_message()
15
+ end
16
+
17
+ its(:class) { should == Hash }
18
+ its(:keys) { should == ['message'] }
19
+ end
20
+
21
+ context 'with all options' do
22
+ subject do
23
+ call.
24
+ should_receive(:make_request!).
25
+ with(:get, "v1/users/:user_id/profile_message", {}, {:array_keys=>["profile_message"]}).
26
+ and_return("message" => nil)
27
+
28
+ call.get_users_profile_message(id: ':user_id')
29
+ end
30
+
31
+ its(:class) { should == Hash }
32
+ its(:keys) { should == ['message'] }
33
+ end
34
+ end
35
+
36
+ describe '#put_users_profile_message' do
37
+ context 'with no options' do
38
+ subject do
39
+ call.
40
+ should_receive(:make_request!).
41
+ with(:put, "v1/users/me/profile_message", {:message=>"some-message"}, {:allowed_codes=>204}).
42
+ and_return(nil)
43
+
44
+ call.put_users_profile_message('some-message')
45
+ end
46
+
47
+ its(:class) { should == NilClass }
48
+ end
49
+
50
+ context 'with all options' do
51
+ subject do
52
+ call.
53
+ should_receive(:make_request!).
54
+ with(:put, "v1/users/:user_id/profile_message", {:message=>"some-message"}, {:allowed_codes=>204}).
55
+ and_return(nil)
56
+
57
+ call.put_users_profile_message('some-message', id: ':user_id')
58
+ end
59
+
60
+ its(:class) { should == NilClass }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Config do
4
+ subject{ XingApiClient.new(nil, nil).send(:config) }
5
+
6
+ describe 'XingApiClient class and instance has a config method' do
7
+ context 'When it gets extended, it...' do
8
+ it 'offers a .config method that offers the config values via methods' do
9
+ XingApiClient.send(:config).request_token_path.should == '/v1/request_token'
10
+ end
11
+ end
12
+
13
+
14
+ context 'When it gets included, it...' do
15
+ it 'offers a #config method that offers the config values via methods' do
16
+ subject.request_token_path.should == '/v1/request_token'
17
+ end
18
+ end
19
+ end
20
+
21
+ shared_examples "only defaults are set" do
22
+ its(:host) { should == 'https://api.xing.com' }
23
+ its(:request_token_path) { should == '/v1/request_token' }
24
+ its(:authorize_path) { should == '/v1/authorize' }
25
+ its(:access_token_path) { should == '/v1/access_token' }
26
+ its(:consumer_secret) { should == nil }
27
+ its(:callback_url) { should == nil }
28
+ end
29
+
30
+ describe 'Default vaulues are available' do
31
+ its(:consumer_key) { should == nil }
32
+ it_behaves_like "only defaults are set"
33
+ end
34
+
35
+ describe '.set' do
36
+ before { XingApiClient::Config.set(consumer_key: 'test_set') }
37
+ its(:consumer_key) { should == 'test_set' }
38
+ it_behaves_like "only defaults are set"
39
+ end
40
+
41
+ describe '.load_file' do
42
+ before do
43
+ YAML.should_receive(:load_file).with('path/file.yml').and_return(consumer_key: 'test_load_file')
44
+ XingApiClient::Config.load_file('path/file.yml')
45
+ end
46
+
47
+ its(:consumer_key) { should == 'test_load_file' }
48
+ it_behaves_like "only defaults are set"
49
+ end
50
+
51
+ describe '.load_env' do
52
+ before do
53
+ ENV.should_receive(:[]).with('XINGAPICLIENT_HOST').and_return(nil)
54
+ ENV.should_receive(:[]).with('XINGAPICLIENT_REQUEST_TOKEN_PATH').and_return(nil)
55
+ ENV.should_receive(:[]).with('XINGAPICLIENT_AUTHORIZE_PATH').and_return(nil)
56
+ ENV.should_receive(:[]).with('XINGAPICLIENT_ACCESS_TOKEN_PATH').and_return(nil)
57
+ ENV.should_receive(:[]).with('XINGAPICLIENT_CONSUMER_KEY').and_return('test_load_env')
58
+ ENV.should_receive(:[]).with('XINGAPICLIENT_CONSUMER_SECRET').and_return(nil)
59
+ ENV.should_receive(:[]).with('XINGAPICLIENT_CALLBACK_URL').and_return(nil)
60
+
61
+ XingApiClient::Config.load_env()
62
+ end
63
+
64
+ its(:consumer_key) { should == 'test_load_env' }
65
+ it_behaves_like "only defaults are set"
66
+ end
67
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Object::User do
4
+ subject do
5
+ XingApiClient::Object::User.new(XingApiClient::Object::User::EXAMPLE_RESPONSE["users"].first)
6
+ end
7
+
8
+ its(:id) { should == '13802856_c7551a' }
9
+ its(:first_name) { should == 'Firstname' }
10
+ its(:last_name) { should == 'Lastname' }
11
+ its(:display_name) { should == 'Firstname Lastname' }
12
+ its(:page_name) { should == 'Firstname_Lastname8' }
13
+ its(:employment_status) { should == 'EMPLOYEE' }
14
+ its(:gender) { should == 'm' }
15
+ its(:birth_date) { should == Date.parse("1983-01-03") }
16
+ its(:active_email) { should == 'somemailaddress@gmail.com' }
17
+ its(:time_zone) { should == {"utc_offset"=>2, "name"=>"Europe/Berlin"} }
18
+ its(:premium_services) { should == ["SEARCH", "PRIVATEMESSAGES"] }
19
+ its(:badges) { should == ["PREMIUM", "MODERATOR"] }
20
+ its(:wants) { should == 'new gems, cool rails stuff, pizza' }
21
+ its(:haves) { should == 'Jenkins CI, MySQL, REST, TDD, UML' }
22
+ its(:interests) { should == 'CSS, CoffeeScript, HTML5, Robotics, jQuery' }
23
+ its(:organisation_member) { should == nil }
24
+ its(:languages) { should == {"en"=>"FLUENT", "de"=>"NATIVE"} }
25
+ its(:private_address) { should be_kind_of XingApiClient::Object::Address }
26
+ its(:business_address) { should be_kind_of XingApiClient::Object::Address }
27
+ its(:web_profiles) { should == {} }
28
+ its(:instant_messaging_accounts) { should == {"skype"=>"username"} }
29
+ its(:professional_experience) { should_not be_empty }
30
+ its(:professional_experience) { subject.professional_experience.all?{ |e| e.kind_of?(XingApiClient::Object::Company) }.should be_true }
31
+ its(:photo_urls) { should == {"large"=>"https://x1.xingassets.com/img/users/3/5/1/238ddffce.13802856,9.140x185.jpg",
32
+ "maxi_thumb"=>"https://x1.xingassets.com/img/users/3/5/1/238ddffce.13802856,9.70x93.jpg",
33
+ "medium_thumb"=>"https://x1.xingassets.com/img/users/3/5/1/238ddffce.13802856,9.57x75.jpg",
34
+ "mini_thumb"=>"https://x1.xingassets.com/img/users/3/5/1/238ddffce.13802856,9.18x24.jpg",
35
+ "thumb"=>"https://x1.xingassets.com/img/users/3/5/1/238ddffce.13802856,9.30x40.jpg"} }
36
+ its(:permalink) { should == 'https://www.xing.com/profile/Firstname_Lastname8' }
37
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Object::YearMonth do
4
+ subject { XingApiClient::Object::YearMonth.new(year_month_string) }
5
+
6
+ describe 'the year month string is nil' do
7
+ let(:year_month_string) { nil }
8
+
9
+ its(:year) { should be_nil }
10
+ its(:month) { should be_nil }
11
+
12
+ its(:to_date) { should == Date.new }
13
+
14
+ it '<=> Date.parse("2000-12-20")' do
15
+ (subject <=> Date.parse("2000-12-20")).should == -1
16
+ end
17
+
18
+ it '<=> .new("2000-12-20")' do
19
+ (subject <=> subject.class.new("2000-12-20")).should == -1
20
+ end
21
+ end
22
+
23
+ describe 'the year month string is empty' do
24
+ let(:year_month_string) { '' }
25
+
26
+ its(:year) { should be_nil }
27
+ its(:month) { should be_nil }
28
+ its(:to_date) { should == Date.new }
29
+
30
+ it '<=> Date.parse("2000-12-20")' do
31
+ (subject <=> Date.parse("2000-12-20")).should == -1
32
+ end
33
+
34
+ it '<=> .new("2000-12")' do
35
+ (subject <=> subject.class.new("2000-12")).should == -1
36
+ end
37
+ end
38
+
39
+ describe 'the year date string contains only a year' do
40
+ let(:year_month_string) { '2010' }
41
+
42
+ its(:year) { should == 2010 }
43
+ its(:month) { should be_nil }
44
+ its(:to_date) { should == Date.parse("2010-1-1") }
45
+
46
+ it '<=> Date.parse("2000-12-20")' do
47
+ (subject <=> Date.parse("2000-12-20")).should == 1
48
+ end
49
+
50
+ it '<=> .new("2000-12")' do
51
+ (subject <=> subject.class.new("2000-12")).should == 1
52
+ end
53
+ end
54
+
55
+ describe 'the year date string contains a year and a month' do
56
+ let(:year_month_string) { '2000-5' }
57
+
58
+ its(:year) { should == 2000 }
59
+ its(:month) { should == 5 }
60
+ its(:to_date) { should == Date.parse("2000-5-1") }
61
+
62
+ it '<=> Date.parse("2000-5-1")' do
63
+ (subject <=> Date.parse("2000-5-1")).should == 0
64
+ end
65
+
66
+ it '<=> .new("2000-5")' do
67
+ (subject <=> subject.class.new("2000-5")).should == 0
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Request::Error do
4
+
5
+ describe '.new' do
6
+ subject do
7
+ XingApiClient::Request::Error.
8
+ new(200, 'RSPEC_EXCEPTION', {error_name: 'RSPEC_EXCEPTION'})
9
+ end
10
+
11
+ its(:code) { should == 200 }
12
+ its(:api_name) { should == 'RSPEC_EXCEPTION' }
13
+ its(:response) { should == {error_name: 'RSPEC_EXCEPTION'} }
14
+ end
15
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe XingApiClient::Request do
4
+ subject { XingApiClient::Request }
5
+ let(:instance){ subject.new(consumer_token_object) }
6
+ let(:consumer_token_object) { double('consumer_token_object') }
7
+
8
+ describe '.new' do
9
+ it 'sets the intsance variable access_token to the argument when it gets initialized' do
10
+ instance.instance_variable_get('@consumer_token').should == consumer_token_object
11
+ end
12
+ end
13
+
14
+ describe '#generate_url_params!' do
15
+ it 'returns a string with url-encoded values' do
16
+ instance.send(:generate_url_params, user_id: '1_abcdef', message: 'abcABC#./_').should == "?user_id=1_abcdef&message=abcABC%23.%2F_"
17
+ end
18
+ end
19
+
20
+ describe '#add_default_values' do
21
+ it 'returns a hash' do
22
+ instance.send(:add_default_values, nil).should == {}
23
+ instance.send(:add_default_values, {}).should == {}
24
+ end
25
+
26
+ it 'returns a hash with all keys' do
27
+ instance.send(:add_default_values, {a: '', b: '', c: ''}).keys.should == [:a, :b, :c]
28
+ end
29
+
30
+ context 'offset' do
31
+ it 'returns an integer' do
32
+ instance.send(:add_default_values, offset: nil).should == { offset: 0 }
33
+ instance.send(:add_default_values, offset: '5').should == { offset: 5 }
34
+ instance.send(:add_default_values, offset: 5).should == { offset: 5 }
35
+ end
36
+ end
37
+
38
+ context 'user_fields' do
39
+ it 'returns a string' do
40
+ instance.send(:add_default_values, user_fields: nil).should == { user_fields: XingApiClient::Object::User::AVAILABLE_FIELDS.join(',') }
41
+ instance.send(:add_default_values, user_fields: 'id,name').should == { user_fields: 'id,name' }
42
+ end
43
+ end
44
+
45
+ context 'other values' do
46
+ it 'returns the values untouched' do
47
+ test_thing = stub('something')
48
+ instance.send(:add_default_values, other: test_thing ).should == { other: test_thing }
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '#handle_error!' do
54
+ context 'If the error is defined, it...' do
55
+ XingApiClient::Request::ERROR_CLASSES.each_pair do |api_error_code, error_class|
56
+ it "raises an #{error_class}" do
57
+ expect { instance.send(:handle_error!,'1234', 'error_name' => api_error_code) }.
58
+ to raise_error( error_class )
59
+ end
60
+ end
61
+ end
62
+
63
+ context 'If the error is undefined, it...' do
64
+ it "raises an XingApiClient::Request::Error" do
65
+ expect { instance.send(:handle_error!,'1234', 'error_name' => 'RSPEC_TEST_EXCEPTION') }.
66
+ to raise_error( XingApiClient::Request::Error )
67
+ end
68
+ end
69
+ end
70
+ end