yammer-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +29 -0
- data/.travis.yml +9 -0
- data/.yardopts +10 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +13 -0
- data/LICENSE.md +20 -0
- data/README.md +265 -0
- data/Rakefile +12 -0
- data/certs/tiabas-public.pem +21 -0
- data/lib/yammer.rb +28 -0
- data/lib/yammer/api.rb +10 -0
- data/lib/yammer/api/autocomplete.rb +25 -0
- data/lib/yammer/api/group.rb +78 -0
- data/lib/yammer/api/group_membership.rb +32 -0
- data/lib/yammer/api/message.rb +196 -0
- data/lib/yammer/api/network.rb +21 -0
- data/lib/yammer/api/notification.rb +18 -0
- data/lib/yammer/api/search.rb +28 -0
- data/lib/yammer/api/thread.rb +23 -0
- data/lib/yammer/api/topic.rb +21 -0
- data/lib/yammer/api/user.rb +156 -0
- data/lib/yammer/client.rb +101 -0
- data/lib/yammer/configurable.rb +46 -0
- data/lib/yammer/error.rb +61 -0
- data/lib/yammer/http_connection.rb +184 -0
- data/lib/yammer/identity_map.rb +42 -0
- data/lib/yammer/model.rb +6 -0
- data/lib/yammer/model/base.rb +133 -0
- data/lib/yammer/model/group.rb +13 -0
- data/lib/yammer/model/group_membership.rb +11 -0
- data/lib/yammer/model/message.rb +17 -0
- data/lib/yammer/model/message_body.rb +13 -0
- data/lib/yammer/model/thread.rb +44 -0
- data/lib/yammer/model/user.rb +46 -0
- data/lib/yammer/response.rb +43 -0
- data/lib/yammer/version.rb +18 -0
- data/spec/api/autocomplete_spec.rb +23 -0
- data/spec/api/group_membership_spec.rb +30 -0
- data/spec/api/group_spec.rb +58 -0
- data/spec/api/message_spec.rb +118 -0
- data/spec/api/network_spec.rb +23 -0
- data/spec/api/notification_spec.rb +23 -0
- data/spec/api/search_spec.rb +23 -0
- data/spec/api/thread_spec.rb +23 -0
- data/spec/api/topic_spec.rb +23 -0
- data/spec/api/user_spec.rb +76 -0
- data/spec/client_spec.rb +208 -0
- data/spec/connection_spec.rb +280 -0
- data/spec/error_spec.rb +69 -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/identity_map_spec.rb +108 -0
- data/spec/model/base_spec.rb +155 -0
- data/spec/model/group_membership_spec.rb +27 -0
- data/spec/model/group_spec.rb +44 -0
- data/spec/model/message_spec.rb +45 -0
- data/spec/model/thread_spec.rb +66 -0
- data/spec/model/user_spec.rb +150 -0
- data/spec/response_spec.rb +66 -0
- data/spec/spec_helper.rb +42 -0
- data/yammer.gemspec +29 -0
- metadata +270 -0
@@ -0,0 +1,133 @@
|
|
1
|
+
module Yammer
|
2
|
+
module Model
|
3
|
+
class Base
|
4
|
+
|
5
|
+
def self.attr_accessor_deffered(*symbols)
|
6
|
+
symbols.each do |key|
|
7
|
+
fetchable_keys[key] = true
|
8
|
+
|
9
|
+
define_method (key.to_s) do
|
10
|
+
if self.class.fetchable_keys.has_key?(key) && !@attrs.has_key?(key) && @id
|
11
|
+
load!
|
12
|
+
end
|
13
|
+
instance_variable_get("@#{key}")
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method ("#{key}=") do |value|
|
17
|
+
if @attrs.fetch(key, false) && !new_record?
|
18
|
+
@modified_attributes[key] = value
|
19
|
+
else
|
20
|
+
@attrs[key] = value
|
21
|
+
end
|
22
|
+
instance_variable_set("@#{key}", value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# @!scope class
|
28
|
+
def self.fetchable_keys
|
29
|
+
@fetchable_keys ||= {}
|
30
|
+
return @fetchable_keys
|
31
|
+
end
|
32
|
+
|
33
|
+
# @!scope class
|
34
|
+
def self.identity_map
|
35
|
+
@identity_map ||= Yammer::IdentityMap.new
|
36
|
+
end
|
37
|
+
|
38
|
+
# @!scope class
|
39
|
+
def self.base_name
|
40
|
+
word = "#{self.name.split(/::/).last}"
|
41
|
+
word.gsub!(/::/, '/')
|
42
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
43
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
44
|
+
word.tr!("-", "_")
|
45
|
+
word.downcase!
|
46
|
+
word
|
47
|
+
end
|
48
|
+
|
49
|
+
# @!scope class
|
50
|
+
def self.fetch(id)
|
51
|
+
return unless identity_map
|
52
|
+
attributes = identity_map.get("#{self.base_name}_#{id}")
|
53
|
+
unless attributes
|
54
|
+
result = Yammer.send("get_#{self.base_name}", id)
|
55
|
+
attributes = result.body || {}
|
56
|
+
unless attributes.empty?
|
57
|
+
identity_map.put("#{self.base_name}_#{id}", attributes)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
attributes
|
61
|
+
end
|
62
|
+
|
63
|
+
# @!scope class
|
64
|
+
def self.get(id)
|
65
|
+
new(fetch(id))
|
66
|
+
end
|
67
|
+
|
68
|
+
attr_reader :id, :attrs
|
69
|
+
|
70
|
+
def initialize(props={})
|
71
|
+
@modified_attributes = {}
|
72
|
+
@attrs = {}
|
73
|
+
@new_record = true
|
74
|
+
self.id = props.delete(:id)
|
75
|
+
self.update(props)
|
76
|
+
end
|
77
|
+
|
78
|
+
def base_name
|
79
|
+
self.class.base_name
|
80
|
+
end
|
81
|
+
|
82
|
+
def new_record?
|
83
|
+
@new_record
|
84
|
+
end
|
85
|
+
|
86
|
+
def changes
|
87
|
+
@modified_attributes
|
88
|
+
end
|
89
|
+
|
90
|
+
def modified?
|
91
|
+
!changes.empty?
|
92
|
+
end
|
93
|
+
|
94
|
+
def load!
|
95
|
+
result = self.class.fetch(@id)
|
96
|
+
update(result)
|
97
|
+
end
|
98
|
+
alias_method :reload!, :load!
|
99
|
+
|
100
|
+
def save
|
101
|
+
return self if ((!new_record? && @modified_attributes.empty?) || @attrs.empty?)
|
102
|
+
result = if new_record?
|
103
|
+
Yammer.send("create_#{self.base_name}", @attrs)
|
104
|
+
else
|
105
|
+
Yammer.send("update_#{self.base_name}", @id, @modified_attributes)
|
106
|
+
end
|
107
|
+
@modified_attributes = {}
|
108
|
+
self
|
109
|
+
end
|
110
|
+
|
111
|
+
def delete!
|
112
|
+
return if new_record?
|
113
|
+
result = Yammer.send("delete_#{self.base_name}", @id)
|
114
|
+
result.success?
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def id=(model_id)
|
120
|
+
return if model_id.nil?
|
121
|
+
@id = model_id.to_i
|
122
|
+
@new_record = false
|
123
|
+
end
|
124
|
+
|
125
|
+
protected
|
126
|
+
def update(props={})
|
127
|
+
props.each do |key, value|
|
128
|
+
send("#{key}=", value)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Yammer
|
2
|
+
class Group < Yammer::Model::Base
|
3
|
+
|
4
|
+
attr_accessor_deffered :show_in_directory, :privacy, :description, :creator_type,
|
5
|
+
:creator_id, :mugshot_id, :stats, :state, :web_url, :name, :created_at, :type,
|
6
|
+
:mugshot_url, :url, :full_name, :mugshot_url_template, :description
|
7
|
+
|
8
|
+
# @!scope class
|
9
|
+
def self.create(params={})
|
10
|
+
result = Yammer.create_group(params)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Yammer
|
2
|
+
class Message < Yammer::Model::Base
|
3
|
+
|
4
|
+
attr_accessor_deffered :direct_message, :privacy, :group_id, :created_at,
|
5
|
+
:attachments, :liked_by, :chat_client_sequence, :client_url, :content_excerpt,
|
6
|
+
:message_type, :url, :web_url, :network_id, :system_message, :client_type,
|
7
|
+
:sender_type, :sender_id, :thread_id, :conversation_id, :replied_to_id, :body
|
8
|
+
|
9
|
+
attr_reader :replied_to_id
|
10
|
+
|
11
|
+
# @!scope class
|
12
|
+
def self.create(params={})
|
13
|
+
Yammer.create_message(params)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Yammer
|
2
|
+
class MessageBody
|
3
|
+
attr_reader :urls, :parsed, :rich
|
4
|
+
attr_accessor :plain
|
5
|
+
|
6
|
+
def initialize(opts={})
|
7
|
+
@plain = opts.fetch(:plain,'')
|
8
|
+
@parsed = opts.fetch(:parsed,'')
|
9
|
+
@rich = opts.fetch(:rich,'')
|
10
|
+
@urls = opts.fetch(:urls,'')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Yammer
|
2
|
+
class Thread < Yammer::Model::Base
|
3
|
+
|
4
|
+
attr_accessor_deffered :participants, :web_url, :references, :thread_starter_id,
|
5
|
+
:type, :privacy, :has_attachments, :attachments_meta, :topics, :url, :attachments,
|
6
|
+
:direct_message, :participants_count, :stats
|
7
|
+
|
8
|
+
def first_reply_id
|
9
|
+
stats[:first_reply_id]
|
10
|
+
end
|
11
|
+
|
12
|
+
def first_reply
|
13
|
+
@first_reply ||= first_reply_id ? Yammer::Message.new(:id => first_reply_id) : nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def latest_reply_id
|
17
|
+
stats[:latest_reply_id]
|
18
|
+
end
|
19
|
+
|
20
|
+
def last_reply
|
21
|
+
@latest_reply ||= latest_reply_id ? Yammer::Message.new(:id => latest_reply_id) : nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def people
|
25
|
+
@people ||= begin
|
26
|
+
@participants.map do |part|
|
27
|
+
next unless part[:type] == 'user'
|
28
|
+
Yammer::User.new(:id => part[:id])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
@people
|
32
|
+
end
|
33
|
+
|
34
|
+
def messages
|
35
|
+
@messages = {}
|
36
|
+
result = Yammer.messages_in_thread(self.id)
|
37
|
+
msgs = result.body[:messages].each do |message|
|
38
|
+
msg = Yammer::Message.new(message)
|
39
|
+
@messages["#{msg.id}"] = msg
|
40
|
+
end
|
41
|
+
@messages
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Yammer
|
2
|
+
class User < Yammer::Model::Base
|
3
|
+
|
4
|
+
# @!scope class
|
5
|
+
def self.create(email)
|
6
|
+
result = Yammer.create_user(:email => email)
|
7
|
+
return nil unless result.created?
|
8
|
+
id = result.headers['Location'].split('/').last.to_i
|
9
|
+
new(:id => id)
|
10
|
+
end
|
11
|
+
|
12
|
+
# @!scope class
|
13
|
+
def self.current
|
14
|
+
result = Yammer.current_user
|
15
|
+
return nil unless result.success?
|
16
|
+
new(result.body)
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_accessor_deffered :first_name, :last_name, :full_name, :hire_date, :mugshot, :state,
|
20
|
+
:type, :admin, :verified_admin, :expertise, :birth_date, :stats, :show_ask_for_photo, :job_title,
|
21
|
+
:web_url, :url, :external_urls, :activated_at, :summary, :department, :previous_companies,
|
22
|
+
:follow_general_messages, :schools, :interests, :significant_other, :network_name, :network_id,
|
23
|
+
:can_broadcast, :web_preferences, :network_domains, :location, :contact, :kids_names, :guid,
|
24
|
+
:name, :mugshot_url, :mugshot_url_template, :settings, :timezone
|
25
|
+
|
26
|
+
def email
|
27
|
+
@email ||= begin
|
28
|
+
self.contact[:email_addresses].map do |e|
|
29
|
+
e[:address] if e[:type] == 'primary'
|
30
|
+
end.first
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def following
|
35
|
+
Yammer.users_followed_by(@id)
|
36
|
+
end
|
37
|
+
|
38
|
+
def followers
|
39
|
+
Yammer.users_following(@id)
|
40
|
+
end
|
41
|
+
|
42
|
+
def update!(params)
|
43
|
+
Yammer.update_user(@id, params)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Yammer
|
2
|
+
class Response
|
3
|
+
|
4
|
+
attr_reader :code, :body, :headers
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@headers = response.header
|
8
|
+
@body = response.body
|
9
|
+
@code = response.code.to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
def raw_body
|
13
|
+
@body
|
14
|
+
end
|
15
|
+
|
16
|
+
def body
|
17
|
+
@parsed_body ||= parse(@body)
|
18
|
+
end
|
19
|
+
|
20
|
+
def empty?
|
21
|
+
@body.nil? || @body.strip.empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
def success?
|
25
|
+
@code == 200
|
26
|
+
end
|
27
|
+
|
28
|
+
def created?
|
29
|
+
@code == 201
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def parse(body)
|
35
|
+
case body
|
36
|
+
when /\A^\s*$\z/, nil
|
37
|
+
nil
|
38
|
+
else
|
39
|
+
MultiJson.load(body, :symbolize_keys => true)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Yammer
|
2
|
+
class Version
|
3
|
+
MAJOR = 0 unless defined? Yammer::MAJOR
|
4
|
+
MINOR = 1 unless defined? Yammer::MINOR
|
5
|
+
PATCH = 0 unless defined? Yammer::PATCH
|
6
|
+
PRE = nil unless defined? Yammer::PRE
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# @return [String]
|
11
|
+
def to_s
|
12
|
+
[MAJOR, MINOR, PATCH, PRE].compact.join('.')
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Yammer::Api::Autocomplete do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
@client = Yammer::Client.new(
|
7
|
+
:site_url => 'https://www.yammer.com',
|
8
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
9
|
+
:client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
|
10
|
+
:access_token => 'TolNOFka9Uls2DxahNi78A',
|
11
|
+
:connection_client => Yammer::HttpConnection
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { @client }
|
16
|
+
|
17
|
+
describe '#autocomplete' do
|
18
|
+
it 'should fetch autocomplete data' do
|
19
|
+
subject.should_receive(:get).with('/api/v1/autocomplete', { :prefix => 'alc' })
|
20
|
+
subject.autocomplete({ :prefix => 'alc' })
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Yammer::Api::GroupMembership do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
@client = Yammer::Client.new(
|
7
|
+
:site_url => 'https://www.yammer.com',
|
8
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
9
|
+
:client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
|
10
|
+
:access_token => 'TolNOFka9Uls2DxahNi78A',
|
11
|
+
:connection_client => Yammer::HttpConnection
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { @client }
|
16
|
+
|
17
|
+
describe '#get_group_membership' do
|
18
|
+
it 'should fetch a group membership' do
|
19
|
+
subject.should_receive(:get).with('/api/v1/group_memberships/1')
|
20
|
+
subject.get_group_membership(1)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#create_group_membership' do
|
25
|
+
it 'should create a group membership' do
|
26
|
+
subject.should_receive(:post).with('/api/v1/group_memberships', { :group_id => 2 })
|
27
|
+
subject.create_group_membership(2)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Yammer::Api::Group do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
@client = Yammer::Client.new(
|
7
|
+
:site_url => 'https://www.yammer.com',
|
8
|
+
:client_id => 'PRbTcg9qjgKsp4jjpm1pw',
|
9
|
+
:client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
|
10
|
+
:access_token => 'TolNOFka9Uls2DxahNi78A',
|
11
|
+
:connection_client => Yammer::HttpConnection
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { @client }
|
16
|
+
|
17
|
+
describe '#all_groups' do
|
18
|
+
it 'should fetch all groups in network' do
|
19
|
+
subject.should_receive(:get).with('/api/v1/groups', {})
|
20
|
+
subject.all_groups
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#groups_for_user' do
|
25
|
+
it 'should fetch all groups for user' do
|
26
|
+
subject.should_receive(:get).with('/api/v1/groups/for_user/2')
|
27
|
+
subject.groups_for_user(2)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#get_group' do
|
32
|
+
it 'should fetch a thread' do
|
33
|
+
subject.should_receive(:get).with('/api/v1/groups/1')
|
34
|
+
subject.get_group(1)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#create_group' do
|
39
|
+
it 'should fetch a thread' do
|
40
|
+
subject.should_receive(:post).with('/api/v1/groups', {
|
41
|
+
:name => 'my group',
|
42
|
+
:description => 'A test group',
|
43
|
+
:private => false
|
44
|
+
})
|
45
|
+
subject.create_group(:name => 'my group', :description => 'A test group', :private => false)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#update_group' do
|
50
|
+
it 'should fetch a thread' do
|
51
|
+
subject.should_receive(:post).with('/api/v1/groups/2', {
|
52
|
+
:name => 'another group',
|
53
|
+
:description => 'A modified group description',
|
54
|
+
})
|
55
|
+
subject.update_group(2, :name => 'another group', :description => 'A modified group description')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|