yam 0.0.6 → 1.0.0
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.
- data.tar.gz.sig +0 -0
- data/.travis.yml +5 -0
- data/.yardopts +10 -0
- data/AUTHORS +1 -0
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +0 -7
- data/Gemfile +27 -1
- data/README.md +190 -67
- data/Rakefile +9 -3
- data/certs/public.pem +20 -0
- data/lib/yammer.rb +47 -0
- data/lib/yammer/api.rb +29 -0
- data/lib/yammer/api/autocomplete.rb +39 -0
- data/lib/yammer/api/group.rb +92 -0
- data/lib/yammer/api/group_membership.rb +46 -0
- data/lib/yammer/api/invitation.rb +39 -0
- data/lib/yammer/api/like.rb +57 -0
- data/lib/yammer/api/message.rb +227 -0
- data/lib/yammer/api/network.rb +35 -0
- data/lib/yammer/api/notification.rb +32 -0
- data/lib/yammer/api/open_graph_object.rb +92 -0
- data/lib/yammer/api/pending_attachment.rb +64 -0
- data/lib/yammer/api/search.rb +42 -0
- data/lib/yammer/api/subscription.rb +32 -0
- data/lib/yammer/api/thread.rb +37 -0
- data/lib/yammer/api/topic.rb +37 -0
- data/lib/yammer/api/user.rb +168 -0
- data/lib/yammer/api_handler.rb +27 -0
- data/lib/yammer/api_response.rb +57 -0
- data/lib/yammer/base.rb +208 -0
- data/lib/yammer/client.rb +100 -0
- data/lib/yammer/configurable.rb +81 -0
- data/lib/yammer/error.rb +75 -0
- data/lib/yammer/group.rb +27 -0
- data/lib/yammer/group_membership.rb +25 -0
- data/lib/yammer/http_adapter.rb +100 -0
- data/lib/yammer/identity_map.rb +56 -0
- data/lib/yammer/message.rb +32 -0
- data/lib/yammer/message_body.rb +27 -0
- data/lib/yammer/pending_attachment.rb +19 -0
- data/lib/yammer/thread.rb +58 -0
- data/lib/yammer/user.rb +66 -0
- data/lib/yammer/version.rb +32 -0
- data/{lib/yam/configuration.rb → spec/api/autocomplete_spec.rb} +18 -23
- data/spec/api/group_membership_spec.rb +48 -0
- data/spec/api/group_spec.rb +76 -0
- data/spec/api/invitation_spec.rb +60 -0
- data/spec/api/like_spec.rb +46 -0
- data/spec/api/message_spec.rb +136 -0
- data/spec/api/network_spec.rb +41 -0
- data/{lib/yam/client.rb → spec/api/notification_spec.rb} +22 -4
- data/spec/api/open_graph_object_spec.rb +67 -0
- data/spec/api/pending_attachment_spec.rb +56 -0
- data/{lib/yam/constants.rb → spec/api/search_spec.rb} +21 -8
- data/spec/api/subscription_spec.rb +41 -0
- data/{lib/yam.rb → spec/api/thread_spec.rb} +19 -12
- data/{lib/yam/request.rb → spec/api/topic_spec.rb} +19 -15
- data/spec/api/user_spec.rb +108 -0
- data/spec/api_response.rb +86 -0
- data/spec/client_spec.rb +364 -0
- data/spec/error_spec.rb +88 -0
- data/spec/fixtures/group.json +1 -0
- data/spec/fixtures/message.json +1 -0
- data/spec/fixtures/messages_in_thread.json +1 -0
- data/spec/fixtures/portal_thread.json +1 -0
- data/spec/fixtures/private_thread.json +1 -0
- data/spec/fixtures/public_thread.json +1 -0
- data/spec/fixtures/user.json +1 -0
- data/spec/fixtures/users_followed.json +1 -0
- data/spec/fixtures/users_following.json +1 -0
- data/spec/http_adapter_spec.rb +109 -0
- data/spec/identity_map_spec.rb +127 -0
- data/spec/mocks/attachment.txt +1 -0
- data/spec/model/base_spec.rb +196 -0
- data/spec/model/group_membership_spec.rb +57 -0
- data/spec/model/group_spec.rb +73 -0
- data/spec/model/message_spec.rb +74 -0
- data/spec/model/thread_spec.rb +91 -0
- data/spec/model/user_spec.rb +222 -0
- data/spec/spec_helper.rb +39 -14
- data/yam.gemspec +50 -28
- metadata +270 -187
- metadata.gz.sig +0 -0
- data/lib/yam/api.rb +0 -53
- data/lib/yam/connection.rb +0 -57
- data/lib/yam/version.rb +0 -20
- data/spec/yam/client_spec.rb +0 -50
- data/spec/yam_spec.rb +0 -87
data/spec/error_spec.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) Microsoft Corporation
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
13
|
+
# ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
|
14
|
+
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
|
15
|
+
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
16
|
+
#
|
17
|
+
# See the Apache Version 2.0 License for specific language governing
|
18
|
+
# permissions and limitations under the License.
|
19
|
+
|
20
|
+
require File.expand_path('../spec_helper', __FILE__)
|
21
|
+
|
22
|
+
describe Yammer::Error do
|
23
|
+
|
24
|
+
subject { Yammer::Error }
|
25
|
+
|
26
|
+
describe 'from status' do
|
27
|
+
|
28
|
+
context 'status unknown' do
|
29
|
+
it 'returns ApiError' do
|
30
|
+
expect(subject.from_status).to eq Yammer::Error::ApiError
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'status 400' do
|
35
|
+
it 'returns BadRequest' do
|
36
|
+
expect(subject.from_status(400)).to eq Yammer::Error::BadRequest
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'status 401' do
|
41
|
+
it 'returns Unauthorized' do
|
42
|
+
expect(subject.from_status(401)).to eq Yammer::Error::Unauthorized
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'status 403' do
|
47
|
+
it 'returns Forbidden' do
|
48
|
+
expect(subject.from_status(403)).to eq Yammer::Error::Forbidden
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'status 404' do
|
53
|
+
it 'returns NotFound' do
|
54
|
+
expect(subject.from_status(404)).to eq Yammer::Error::NotFound
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'status 406' do
|
59
|
+
it 'returns NotAcceptable' do
|
60
|
+
expect(subject.from_status(406)).to eq Yammer::Error::NotAcceptable
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'status 429' do
|
65
|
+
it 'returns RateLimitExceeded' do
|
66
|
+
expect(subject.from_status(429)).to eq Yammer::Error::RateLimitExceeded
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'status 500' do
|
71
|
+
it 'returns InternalServerError' do
|
72
|
+
expect(subject.from_status(500)).to eq Yammer::Error::InternalServerError
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'status 502' do
|
77
|
+
it 'returns BadGateway' do
|
78
|
+
expect(subject.from_status(502)).to eq Yammer::Error::BadGateway
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'status 503' do
|
83
|
+
it 'returns ServiceUnavailable' do
|
84
|
+
expect(subject.from_status(503)).to eq Yammer::Error::ServiceUnavailable
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"show_in_directory":"true","privacy":"public","description":"WE KNOW PURPLE","id":2528,"creator_type":"user","creator_id":98981,"mugshot_id":"Z9SwsZvd3zr-Gm5G23wjvXDpcS0VGhJv","stats":{"last_message_at":"2013/01/05 20:43:43 +0000","members":55,"updates":7088,"last_message_id":10825877},"state":"active","web_url":"https://www.yammer.com/yammer-inc.com/groups/railsteam","name":"railsteam","created_at":"2012/02/02 23:17:35 +0000","type":"group","mugshot_url":"https://mug0.staging.assets-yammer.com/mugshot/images/48x48/Z9SwsZvd3zr-Gm5G23wjvXDpcS0VGhJv","url":"https://www.yammer.com/api/v1/groups/2528","mugshot_url_template":"https://mug0.staging.assets-yammer.com/mugshot/images/{width}x{height}/Z9SwsZvd3zr-Gm5G23wjvXDpcS0VGhJv","full_name":"RAILS TEAM"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"id":5,"thread_id":5,"replied_to_id":null,"sender_type":"user","attachments":[],"chat_client_sequence":null,"group_id":7,"web_url":"https://www.yammer.com/yammer-inc.com/messages/5","content_excerpt":"I don't always drink beer. But when I do, I drink Dos Equis","sender_id":67,"client_url":"https://www.yammer.com/","message_type":"update","created_at":"2012/12/08 01:23:16 +0000","network_id":8,"url":"https://www.yammer.com/api/v1/messages/5","system_message":false,"direct_message":false,"privacy":"public","body":{"plain":"I don't always drink beer. But when I do, I drink Dos Equis.","rich":"I don't always drink beer. But when I do, I drink Dos Equi.","parsed":"I don't always drink beer. But when I do, I drink Dos Equis."},"liked_by":{"count":0,"names":[]},"client_type":"Web"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"meta":{"followed_references":[],"feed_name":"Conversation","realtime":{"channel_id":"MTM6MTU0ODg6MTA5Mjg1MDg","authentication_token":"RyPh56vMMc01+XufSYwkN3ITxNbHyxfVRM4oDgUfaEh4nKtWKi1OLVKyMrQwMbQ0NtZRykstKc8vygaKmJpYWOgopVYUZBZVArnGZqYWloYGpga1AJI2DrI=","uri":"https://2.rt.yammer.com/cometd/"},"requested_poll_interval":60,"direct_from_body":false,"feed_desc":"Messages in this conversation","ymodules":[],"current_user_id":1841933,"followed_user_ids":[1908103]},"threaded_extended":{},"messages":[{"client_url":"https://www.yammer.com/","sender_type":"user","client_type":"Web","direct_message":true,"content_excerpt":"Here are some queries that pulls the thread_id (of threads from the last few months) and lets us know information about them, like is on the thread, who likes the thread, topics, what group the thread is in, how many times the thread has been shared, if there are attachements, etc....\n\nhttp://analytics.int.yammer.com/queries/2245/executions/74563\nhttp://analytics.int.yammer.com/queries/2252/executions/74592\nhttp://analytics.int.yammer.com/queries/2251/executions/74582\n\nWe need to put these tables into python for the start of the analysis.","attachments":[{"description":null,"id":3489814542165986,"object_type":"page","inline_url":"blank.html","web_url":"http://analytics.int.yammer.com/queries/2245/executions/74563","name":"http://analytics.int.yammer.com/queries/2245/executions/74563","ymodule":{"web_app_id":"open_graph_object","icon_url":"blank.gif","app_id":"blank"},"type":"ymodule","object_name":"Yammer","inline_html":"\u003Cdiv class=\"yj-open-graph-object ymodule-instance\" data-ymodule-instance=\"3489814542165986\"\u003E\n \u003Cdiv class=\"ymodule-instance-3489814542165986-container-1 yj-open-graph-no-image yj-open-graph-contents\"\u003E\n \u003Ch5 class=\"yj-title\"\u003E\n \u003Cspan\u003E\u003Ca href=\"http://analytics.int.yammer.com/queries/2245/executions/74563\" target=\"_blank\" rel=\"nofollow\"\n \u003E\n http://analytics.int.yammer.com/queries/2245/executions/74563\n \u003C/a\u003E\u003C/span\u003E\n \u003C/h5\u003E\n \u003Ch6 class=\"yj-subtitle\"\u003E\n \u003Cspan\u003Eanalytics.int.yammer.com\u003C/span\u003E\n \u003C/h6\u003E\n \u003C/div\u003E\n \u003Cdiv class=\"yj-actions-container\"\u003E\u003C/div\u003E\n\u003C/div\u003E\n","host_url":null,"thumbnail_url":null,"record_id":348981453123585}],"body":{"urls":["http://analytics.int.yammer.com/queries/2245/executions/74563","http://analytics.int.yammer.com/queries/2252/executions/74592","http://analytics.int.yammer.com/queries/2251/executions/74582"],"parsed":"Here are some queries that pulls the thread_id (of threads from the last few months) and lets us know information about them, like is on the thread, who likes the thread, topics, what group the thread is in, how many times the thread has been shared, if there are attachements, etc....\n\nhttp://analytics.int.yammer.com/queries/2245/executions/74563\nhttp://analytics.int.yammer.com/queries/2252/executions/74592\nhttp://analytics.int.yammer.com/queries/2251/executions/74582\n\nWe need to put these tables into python for the start of the analysis.","plain":"Here are some queries that pulls the thread_id (of threads from the last few months) and lets us know information about them, like is on the thread, who likes the thread, topics, what group the thread is in, how many times the thread has been shared, if there are attachements, etc....\n\nhttp://analytics.int.yammer.com/queries/2245/executions/74563\nhttp://analytics.int.yammer.com/queries/2252/executions/74592\nhttp://analytics.int.yammer.com/queries/2251/executions/74582\n\nWe need to put these tables into python for the start of the analysis.","rich":"Here are some queries that pulls the thread_id (of threads from the last few months) and lets us know information about them, like is on the thread, who likes the thread, topics, what group the thread is in, how many times the thread has been shared, if there are attachements, etc....\u003Cbr\u003E\u003Cbr\u003E\u003Ca href=\"http://analytics.int.yammer.com/queries/2245/executions/74563\" title=\"http://analytics.int.yammer.com/queries/2245/executions/74563\" target=\"_blank\" rel=\"nofollow\"\u003Ehttp://analytics.int.yammer.com/queries/2245/executions/7456\u2026\u003C/a\u003E\u003Cbr\u003E\u003Ca href=\"http://analytics.int.yammer.com/queries/2252/executions/74592\" title=\"http://analytics.int.yammer.com/queries/2252/executions/74592\" target=\"_blank\" rel=\"nofollow\"\u003Ehttp://analytics.int.yammer.com/queries/2252/executions/7459\u2026\u003C/a\u003E\u003Cbr\u003E\u003Ca href=\"http://analytics.int.yammer.com/queries/2251/executions/74582\" title=\"http://analytics.int.yammer.com/queries/2251/executions/74582\" target=\"_blank\" rel=\"nofollow\"\u003Ehttp://analytics.int.yammer.com/queries/2251/executions/7458\u2026\u003C/a\u003E\u003Cbr\u003E\u003Cbr\u003EWe need to put these tables into python for the start of the analysis."},"id":10930136,"conversation_id":324414,"system_message":false,"privacy":"private","chat_client_sequence":null,"network_id":15488,"liked_by":{"names":[],"count":0},"web_url":"https://www.yammer.com/yammer-inc.com/messages/10930136","sender_id":1908103,"created_at":"2013/03/13 21:08:48 +0000","replied_to_id":10930053,"message_type":"update","thread_id":10928508,"url":"https://www.yammer.com/api/v1/messages/10930136"}]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"topics":[],"attachments":[],"direct_message":true,"privacy":"private","id":10939086,"participants_count":2,"stats":{"latest_reply_at":"2013/03/14 20:24:27 +0000","shares":0,"first_reply_at":"2013/03/14 20:24:27 +0000","latest_reply_id":10939089,"first_reply_id":10939089,"updates":2},"has_attachments":false,"web_url":"https://www.yammer.com/yammer-inc.com/#/Threads/show?threadId=10939086","participants":[{"id":1841933,"type":"user"}],"thread_starter_id":10939086,"attachments_meta":{"more_files":false,"more_images":false},"type":"thread","references":[{"id":1841933,"presence":{"client":"Web","status":"online"},"web_url":"https://www.yammer.com/yammer-inc.com/users/kmutyaba","activated_at":"2012/01/23 17:01:02 +0000","state":"active","stats":{"following":60,"followers":82,"updates":1612},"type":"user","name":"kmutyaba","job_title":"Web dev","mugshot_url":"https://mug0.staging.assets-yammer.com/mugshot/images/48x48/c2QF5GN-5WsGdPGL7lGfrr6lP4kljdCj","mugshot_url_template":"https://mug0.staging.assets-yammer.com/mugshot/images/{width}x{height}/c2QF5GN-5WsGdPGL7lGfrr6lP4kljdCj","url":"https://www.yammer.com/api/v1/users/1841933","full_name":"Kevin Mutyaba"}],"url":"https://www.yammer.com/api/v1/messages/in_thread/10939086"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"has_attachments":false,"stats":{"shares":0,"first_reply_id":22,"latest_reply_at":"2013/04/06 17:05:46 +0000","latest_reply_id":25,"updates":2,"first_reply_at":"2013/04/06 17:05:46 +0000"},"attachments_meta":{"more_images":false,"more_files":false},"topics":[],"thread_starter_id":22,"url":"https://www.staging.yammer.com/api/v1/messages/in_thread/22","web_url":"https://www.yammer.com/yammer-inc.com/#/Threads/show?threadId=22","privacy":"public","attachments":[],"direct_message":false,"references":[],"type":"thread","id":22,"participants":[{"id":1841933,"type":"user"},{"id":225553,"type":"user"}],"participants_count":2}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"has_attachments":false,"stats":{"shares":0,"first_reply_id":11,"latest_reply_at":"2013/04/06 17:05:46 +0000","latest_reply_id":13,"updates":2,"first_reply_at":"2013/04/06 17:05:46 +0000"},"attachments_meta":{"more_images":false,"more_files":false},"topics":[],"thread_starter_id":11,"url":"https://www.staging.yammer.com/api/v1/messages/in_thread/11","web_url":"https://www.yammer.com/yammer-inc.com/#/Threads/show?threadId=11","privacy":"public","attachments":[],"direct_message":false,"references":[],"type":"thread","id":11,"participants":[{"id":1841933,"type":"user"},{"id":115553,"type":"user"}],"participants_count":2}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"last_name":"Smith","network_domains":["yammer-inc.com"],"timezone":"Pacific Time (US & Canada)","id":2,"expertise":"","birth_date":"","contact":{"im":{"username":"","provider":"aim"},"has_fake_email":false,"email_addresses":[{"address":"jsmith@yammer-inc.com","type":"primary"}],"phone_numbers":[{"number":"6616007618","type":"mobile"}]},"interests":"","verified_admin":"false","first_name":"John","guid":null,"web_preferences":{"dismissed_feed_tooltip":false,"show_full_names":"true","dismissed_invite_tooltip":true,"network_settings":{"admin_can_delete_messages":"true","allow_external_sharing":true,"message_prompt":"What are you working on?","show_communities_directory":true,"allow_yammer_apps":true,"allow_inline_document_view":true,"enable_private_messages":true,"allow_attachments":"true","enable_chat":true,"allow_inline_video":true,"enable_groups":true},"dismissed_profile_prompt":true,"sticky_my_feed":false,"enter_does_not_submit_message":"true","dismissed_invite_tooltip_at":"2012/09/26 22:43:29 +0000","home_tabs":[{"feed_description":"This feed shows RSS messages you're following.","select_name":"RSS","name":"RSS","type":"followed_bots","ordering_index":"8","url":"https://www.staging.yammer.com/api/v1/messages/followed_bots"},{"group_id":1,"feed_description":"This feed shows messages in this group.","select_name":"Yammer TIME!","name":"Yammer TIME!","type":"group","ordering_index":"46","private":false,"url":"https://www.staging.yammer.com/api/v1/messages/in_group/997"}],"absolute_timestamps":"false","enable_chat":"true","dismissed_apps_tooltip":true,"threaded_mode":"true","prescribed_my_feed":"algo","dismissed_group_tooltip":false,"preferred_my_feed":"following"},"network_id":1,"location":"San Francisco","admin":"false","can_broadcast":"false","external_urls":[],"significant_other":"","stats":{"following":4,"followers":5,"updates":3},"state":"active","activated_at":"2012/01/23 17:01:02 +0000","web_url":"https://www.staging.yammer.com/yammer-inc.com/users/jsmith","schools":[],"name":"jsmith","kids_names":"","follow_general_messages":false,"network_name":"Yammer Staging","type":"user","mugshot_url":"https://mug0.staging.assets-yammer.com/mugshot/images/48x48/c2QF5GN-5WsGdPGL7lGfrr6lP4kljdCj","show_ask_for_photo":false,"job_title":"Web dev","summary":"","department":"Engineering","url":"https://www.staging.yammer.com/api/v1/users/1841933","mugshot_url_template":"https://mug0.staging.assets-yammer.com/mugshot/images/{width}x{height}/c2QF5GN-5WsGdPGL7lGfrr6lP4kljdCj","previous_companies":[],"settings":{"xdr_proxy":"https://stagexdrproxy.yammer.com"},"hire_date":null,"full_name":"John Smith"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"users":[{"activated_at":"2012/02/22 21:21:39 +0000","url":"https://www.staging.yammer.com/api/v1/users/9","web_url":"https://www.staging.yammer.com/salmonellaville.com/users/jim","full_name":"Jimmy","type":"user","state":"active","mugshot_url_template":"https://mug0.staging.assets-yammer.com/mugshot/images/{width}x{height}/HsmbxsFhqsq05tb-VBfxkv937-hN3CWL","job_title":"Grumbler","stats":{"following":69,"updates":353,"followers":76},"mugshot_url":"https://mug0.staging.assets-yammer.com/mugshot/images/48x48/HsmbxsFhqsq05tb-VBfxkv937-hN3CWL","id":9,"name":"jim"}],"more_available":false,"meta":{"followed_user_ids":[9]}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"users":[{"activated_at":"2012/02/22 21:21:39 +0000","url":"https://www.staging.yammer.com/api/v1/users/7","web_url":"https://www.staging.yammer.com/salmonellaville.com/users/jim","full_name":"Jimmy","type":"user","state":"active","mugshot_url_template":"https://mug0.staging.assets-yammer.com/mugshot/images/{width}x{height}/HsmbxsFhqsq05tb-VBfxkv937-hN3CWL","job_title":"Bumbler","stats":{"following":69,"updates":353,"followers":76},"mugshot_url":"https://mug0.staging.assets-yammer.com/mugshot/images/48x48/HsmbxsFhqsq05tb-VBfxkv937-hN3CWL","id":7,"name":"jim"}],"more_available":false,"meta":{"followed_user_ids":[7]}}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) Microsoft Corporation
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
13
|
+
# ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
|
14
|
+
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
|
15
|
+
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
16
|
+
#
|
17
|
+
# See the Apache Version 2.0 License for specific language governing
|
18
|
+
# permissions and limitations under the License.
|
19
|
+
|
20
|
+
require File.expand_path('../spec_helper', __FILE__)
|
21
|
+
require 'yammer/http_adapter'
|
22
|
+
|
23
|
+
describe Yammer::HttpAdapter do
|
24
|
+
|
25
|
+
before :all do
|
26
|
+
Yammer.configure do |conf|
|
27
|
+
conf.access_token = 'TolNOFka9Uls2DxahNi78A'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "initialization" do
|
32
|
+
context "with user options" do
|
33
|
+
|
34
|
+
before do
|
35
|
+
@options = {
|
36
|
+
:verify_ssl => false,
|
37
|
+
:max_redirects => 2
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
subject { @conn = Yammer::HttpAdapter.new('https://www.example.com', @options) }
|
42
|
+
|
43
|
+
it "overrides default options" do
|
44
|
+
expect(subject.instance_variable_get(:"@connection_options")).to eq @options
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with invalid url" do
|
49
|
+
it "should raise argument error" do
|
50
|
+
expect { Yammer::HttpAdapter.new('www.example.com') }.to raise_error(ArgumentError)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with no options" do
|
56
|
+
|
57
|
+
subject { @conn = Yammer::HttpAdapter.new('https://www.yammer.com') }
|
58
|
+
|
59
|
+
describe "#scheme" do
|
60
|
+
it "returns the http scheme" do
|
61
|
+
expect(subject.scheme).to eq 'https'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#host" do
|
66
|
+
it "returns the host server" do
|
67
|
+
expect(subject.host).to eq 'www.yammer.com'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "site_url" do
|
72
|
+
it "returns site_url" do
|
73
|
+
expect(subject.site_url).to eq 'https://www.yammer.com'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "site_url=" do
|
78
|
+
it "sets new site_url on client" do
|
79
|
+
subject.site_url = 'https://www.elpmaxe.com'
|
80
|
+
expect(subject.site_url).to eq 'https://www.elpmaxe.com'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "connection_options=" do
|
85
|
+
it "sets new connection_options" do
|
86
|
+
subject.connection_options = { :max_redirects => 6 }
|
87
|
+
expect(subject.connection_options).to eq({ :max_redirects => 6 })
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should raise error" do
|
91
|
+
expect { subject.connection_options = '' }.to raise_error(ArgumentError)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#absolute_url" do
|
96
|
+
context "with no parameters" do
|
97
|
+
it "returns a uri without path" do
|
98
|
+
expect(subject.send(:absolute_url)).to eq "https://www.yammer.com"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "with parameters" do
|
103
|
+
it "returns a uri with path" do
|
104
|
+
expect(subject.send(:absolute_url, '/oauth/v2/authorize')).to eq "https://www.yammer.com/oauth/v2/authorize"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) Microsoft Corporation
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
13
|
+
# ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
|
14
|
+
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
|
15
|
+
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
16
|
+
#
|
17
|
+
# See the Apache Version 2.0 License for specific language governing
|
18
|
+
# permissions and limitations under the License.
|
19
|
+
|
20
|
+
require File.expand_path('../spec_helper', __FILE__)
|
21
|
+
require 'yammer/identity_map'
|
22
|
+
|
23
|
+
describe Yammer::IdentityMap do
|
24
|
+
|
25
|
+
subject { Yammer::IdentityMap.new }
|
26
|
+
|
27
|
+
after :each do
|
28
|
+
subject.purge!
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'after initialization' do
|
32
|
+
describe '#size' do
|
33
|
+
it 'should be zero' do
|
34
|
+
expect(subject.size).to eq 0
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#get' do
|
39
|
+
context 'with string parameter' do
|
40
|
+
it 'should return nil' do
|
41
|
+
expect(subject.get(:key)).to eq nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with symbol parameter' do
|
46
|
+
it 'should return nil' do
|
47
|
+
expect(subject.get('key')).to eq nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with data' do
|
54
|
+
describe '#put' do
|
55
|
+
context 'with nil key' do
|
56
|
+
it 'should throw exception' do
|
57
|
+
expect { subject.put(nil, 'value') }.to raise_error(Yammer::IdentityMap::InvalidKeyError)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with empty string' do
|
62
|
+
it 'should throw exception' do
|
63
|
+
expect { subject.put('', 'value') }.to raise_error(Yammer::IdentityMap::InvalidKeyError)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should store new value' do
|
68
|
+
subject.put('user_1', 'smith')
|
69
|
+
expect(subject.size).to eq 1
|
70
|
+
expect(subject.get('user_1')).to eq 'smith'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should overwrite existing value' do
|
74
|
+
subject.put('user_1', 'smith')
|
75
|
+
subject.put('user_1', 'john')
|
76
|
+
expect(subject.size).to eq 1
|
77
|
+
expect(subject.get('user_1')).to eq 'john'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#get' do
|
82
|
+
context 'with nil key' do
|
83
|
+
it 'should throw exception' do
|
84
|
+
expect(subject.get(nil)).to eq nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'with empty string' do
|
89
|
+
it 'should throw exception' do
|
90
|
+
expect(subject.get('')).to eq nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context 'with valid key' do
|
95
|
+
it 'should return a value' do
|
96
|
+
subject.put('user_1', 'smith')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'with valid key and default value' do
|
101
|
+
it 'should return default' do
|
102
|
+
subject.put('user_1', 'smith')
|
103
|
+
expect(subject.get('user_1', 'test')).to eq 'smith'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with invalid key and default value' do
|
108
|
+
it 'should return default' do
|
109
|
+
expect(subject.get('user_1', 'test')).to eq 'test'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#purge!' do
|
116
|
+
before do
|
117
|
+
subject.put('user_1', 'smith')
|
118
|
+
subject.put('user_2', 'john')
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'empties the map' do
|
122
|
+
expect(subject.size).to eq 2
|
123
|
+
subject.purge!
|
124
|
+
expect(subject.size).to eq 0
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
The Enterprise Social Network
|
@@ -0,0 +1,196 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# Copyright (c) Microsoft Corporation
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
13
|
+
# ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
|
14
|
+
# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
|
15
|
+
# PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
|
16
|
+
#
|
17
|
+
# See the Apache Version 2.0 License for specific language governing
|
18
|
+
# permissions and limitations under the License.
|
19
|
+
|
20
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
21
|
+
|
22
|
+
describe Yammer::Base do
|
23
|
+
|
24
|
+
class DummyModel < Yammer::Base
|
25
|
+
attr_accessor_deffered :first_name, :last_name
|
26
|
+
end
|
27
|
+
|
28
|
+
class Yammer::Client
|
29
|
+
def update_dummy_model(id, opts={})
|
30
|
+
put("/api/v1/dummy_models/#{id}", opts)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
before :all do
|
35
|
+
Yammer.configure do |conf|
|
36
|
+
conf.access_token = 'TolNOFka9Uls2DxahNi78A'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
after :all do
|
41
|
+
Yammer.reset!
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'new user object with id' do
|
45
|
+
|
46
|
+
subject { DummyModel.new(:id => 42) }
|
47
|
+
|
48
|
+
describe "#id" do
|
49
|
+
it 'should be 42' do
|
50
|
+
expect(subject.id).to eq 42
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#id=" do
|
55
|
+
it 'sets id' do
|
56
|
+
subject.send(:"id=", 2)
|
57
|
+
expect(subject.id).to eq 2
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#new_record?" do
|
62
|
+
it 'returns false' do
|
63
|
+
expect(subject.new_record?).to eq false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#modified?" do
|
68
|
+
|
69
|
+
context 'new model and no changes' do
|
70
|
+
it 'returns false' do
|
71
|
+
model = DummyModel.new(:first_name => 'jim', :last_name => 'peters')
|
72
|
+
expect(model.modified?).to eq false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'new model and no changes' do
|
77
|
+
it 'returns false' do
|
78
|
+
model = DummyModel.new(:first_name => 'mary', :last_name => 'jane')
|
79
|
+
model.last_name = 'jim'
|
80
|
+
model.last_name = 'smithy'
|
81
|
+
expect(model.modified?).to eq false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'persisted model and no changes' do
|
86
|
+
it 'returns true' do
|
87
|
+
model = DummyModel.new(:id => 12, :first_name => 'jim', :last_name => 'peters')
|
88
|
+
expect(model.modified?).to eq false
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'persisted model and changes' do
|
93
|
+
it 'returns true' do
|
94
|
+
model = DummyModel.new(:id => 42, :first_name => 'jim', :last_name => 'peters')
|
95
|
+
model.last_name = 'smithy'
|
96
|
+
expect(model.modified?).to eq true
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#changes" do
|
102
|
+
it 'returns empty hash' do
|
103
|
+
expect(subject.changes).to eq({})
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#save" do
|
108
|
+
it 'returns true' do
|
109
|
+
stub_request(:put, "https://www.yammer.com/api/v1/dummy_models/42").with(
|
110
|
+
:body => {"last_name"=>"smithy"},
|
111
|
+
:headers => {
|
112
|
+
'Accept' =>'application/json',
|
113
|
+
'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
|
114
|
+
'Content-Type' =>'application/x-www-form-urlencoded',
|
115
|
+
'User-Agent' =>"Yammer Ruby Gem #{Yammer::Version}"})
|
116
|
+
model = DummyModel.new(:id => 42, :first_name => 'jim', :last_name => 'peters')
|
117
|
+
model.last_name = 'smithy'
|
118
|
+
model.save
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "#update" do
|
123
|
+
it 'should update the attributes' do
|
124
|
+
# implement
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#base_name" do
|
129
|
+
it 'returns true' do
|
130
|
+
expect(subject.base_name).to eq 'dummy_model'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "setters" do
|
135
|
+
it 'should update modified attributes hash' do
|
136
|
+
subject
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "#save" do
|
141
|
+
|
142
|
+
context 'unmodified model' do
|
143
|
+
it 'does nothing' do
|
144
|
+
expect(subject.save).to eq subject
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'modified model' do
|
149
|
+
subject { DummyModel.new(:id => 42, :first_name => 'jim', :last_name => 'peters') }
|
150
|
+
|
151
|
+
it 'should update model' do
|
152
|
+
api_handler = double("ApiHandler")
|
153
|
+
api_handler.should_receive(:update_dummy_model).with(42, hash_including(
|
154
|
+
:first_name =>'john',
|
155
|
+
:last_name => 'smith')
|
156
|
+
).and_return(double('Response', :success? => true, :created? => true, :body => {:id => 2}))
|
157
|
+
|
158
|
+
subject.stub(:api_handler).and_return(api_handler)
|
159
|
+
subject.first_name = 'john'
|
160
|
+
subject.last_name = 'smith'
|
161
|
+
subject.save
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'unmodified new model' do
|
166
|
+
subject { DummyModel.new(:first_name => 'jim', :last_name => 'peters') }
|
167
|
+
|
168
|
+
it 'should do nothing' do
|
169
|
+
api_handler = double("ApiHandler")
|
170
|
+
api_handler.should_receive(:create_dummy_model).with(
|
171
|
+
hash_including(:first_name =>'jim', :last_name => 'peters')
|
172
|
+
).and_return(double('Response', :success? => true, :created? => true, :body => {:id => '2'}))
|
173
|
+
|
174
|
+
subject.stub(:api_handler).and_return(api_handler)
|
175
|
+
subject.save
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'modified new model' do
|
180
|
+
subject { DummyModel.new(:first_name => 'jim', :last_name => 'peters') }
|
181
|
+
|
182
|
+
it 'should create model' do
|
183
|
+
api_handler = double("ApiHandler")
|
184
|
+
api_handler.should_receive(:create_dummy_model).with({
|
185
|
+
:first_name =>'john',
|
186
|
+
:last_name => 'peters'
|
187
|
+
}).and_return(double('Response', :success? => true, :created? => true, :body => {:id => 2}))
|
188
|
+
|
189
|
+
subject.stub(:api_handler).and_return(api_handler)
|
190
|
+
subject.first_name = 'john'
|
191
|
+
subject.save
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|