yammer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.yardopts +9 -0
- data/Gemfile +2 -0
- data/HISTORY.md +3 -0
- data/LICENSE.md +21 -0
- data/README.md +11 -0
- data/Rakefile +1 -0
- data/lib/faraday/request/gateway.rb +18 -0
- data/lib/faraday/request/multipart_with_file.rb +34 -0
- data/lib/faraday/request/yammer_oauth.rb +24 -0
- data/lib/faraday/response/raise_http_4xx.rb +43 -0
- data/lib/faraday/response/raise_http_5xx.rb +24 -0
- data/lib/yammer.rb +26 -0
- data/lib/yammer/api.rb +24 -0
- data/lib/yammer/authentication.rb +25 -0
- data/lib/yammer/client.rb +18 -0
- data/lib/yammer/client/feed.rb +124 -0
- data/lib/yammer/client/messages.rb +29 -0
- data/lib/yammer/configuration.rb +87 -0
- data/lib/yammer/connection.rb +44 -0
- data/lib/yammer/error.rb +51 -0
- data/lib/yammer/request.rb +49 -0
- data/lib/yammer/version.rb +4 -0
- data/yammer.gemspec +32 -0
- metadata +225 -0
data/.gitignore
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/HISTORY.md
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2011, Bruno Mattarollo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
The Yammer Ruby Gem
|
2
|
+
====================
|
3
|
+
A Ruby wrapper for the Yammer REST APIs
|
4
|
+
|
5
|
+
This wrapper is heavily inspired by the [Twitter](https://github.com/jnunemaker/twitter) Ruby Gem (which is AWESOME and you should definitely check)
|
6
|
+
|
7
|
+
|
8
|
+
Copyright
|
9
|
+
---------
|
10
|
+
Copyright (c) 2011, Bruno Mattarollo
|
11
|
+
See [LICENSE](https://github.com/bruno/yammer/blob/master/LICENSE.md) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module Faraday
|
5
|
+
# @private
|
6
|
+
class Request::Gateway < Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
url = env[:url].dup
|
9
|
+
url.host = @gateway
|
10
|
+
env[:url] = url
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(app, gateway)
|
15
|
+
@app, @gateway = app, gateway
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module Faraday
|
5
|
+
# @private
|
6
|
+
class Request::MultipartWithFile < Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
if env[:body].is_a?(Hash)
|
9
|
+
env[:body].each do |key, value|
|
10
|
+
if value.is_a?(File)
|
11
|
+
env[:body][key] = Faraday::UploadIO.new(value, mime_type(value), value.path)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def mime_type(file)
|
22
|
+
case file.path
|
23
|
+
when /\.jpe?g/i
|
24
|
+
'image/jpeg'
|
25
|
+
when /\.gif$/i
|
26
|
+
'image/gif'
|
27
|
+
when /\.png$/i
|
28
|
+
'image/png'
|
29
|
+
else
|
30
|
+
'application/octet-stream'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Request::YammerOAuth < Faraday::Middleware
|
5
|
+
dependency 'simple_oauth'
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
params = env[:body] || {}
|
9
|
+
signature_params = params
|
10
|
+
|
11
|
+
params.map{ |k,v| signature_params = {} if v.respond_to?(:content_type) }
|
12
|
+
|
13
|
+
header = SimpleOAuth::Header.new(env[:method], env[:url], signature_params, @options)
|
14
|
+
|
15
|
+
env[:request_headers]['Authorization'] = header.to_s
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(app, options)
|
21
|
+
@app, @options = app, options
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module Faraday
|
5
|
+
# @private
|
6
|
+
class Response::RaiseHttp4xx < Response::Middleware
|
7
|
+
def on_complete(env)
|
8
|
+
case env[:status].to_i
|
9
|
+
when 400
|
10
|
+
raise Yammer::BadRequest.new(error_message(env), env[:response_headers])
|
11
|
+
when 401
|
12
|
+
raise Yammer::Unauthorized.new(error_message(env), env[:response_headers])
|
13
|
+
when 403
|
14
|
+
raise Yammer::Forbidden.new(error_message(env), env[:response_headers])
|
15
|
+
when 404
|
16
|
+
raise Yammer::NotFound.new(error_message(env), env[:response_headers])
|
17
|
+
when 406
|
18
|
+
raise Yammer::NotAcceptable.new(error_message(env), env[:response_headers])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def error_message(env)
|
25
|
+
"#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}#{error_body(env[:body])}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def error_body(body)
|
29
|
+
if body.nil?
|
30
|
+
nil
|
31
|
+
elsif body['error']
|
32
|
+
": #{body['error']}"
|
33
|
+
elsif body['errors']
|
34
|
+
first = Array(body['errors']).first
|
35
|
+
if first.kind_of? Hash
|
36
|
+
": #{first['message'].chomp}"
|
37
|
+
else
|
38
|
+
": #{first.chomp}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module Faraday
|
5
|
+
# @private
|
6
|
+
class Response::RaiseHttp5xx < Response::Middleware
|
7
|
+
def on_complete(env)
|
8
|
+
case env[:status].to_i
|
9
|
+
when 500
|
10
|
+
raise Yammer::InternalServerError.new(error_message(env, "Something is technically wrong."), env[:response_headers])
|
11
|
+
when 502
|
12
|
+
raise Yammer::BadGateway.new(error_message(env, "Yammer is down or being upgraded."), env[:response_headers])
|
13
|
+
when 503
|
14
|
+
raise Yammer::ServiceUnavailable.new(error_message(env, "(__-){ Yammer is over capacity."), env[:response_headers])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def error_message(env, body=nil)
|
21
|
+
"#{env[:method].to_s.upcase} #{env[:url].to_s}: #{[env[:status].to_s + ':', body].compact.join(' ')} Check http://status.Yammer.com/ for updates on the status of the Yammer service."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/yammer.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'yammer/api'
|
2
|
+
require 'yammer/client'
|
3
|
+
require 'yammer/configuration'
|
4
|
+
require 'yammer/error'
|
5
|
+
|
6
|
+
module Yammer
|
7
|
+
extend Configuration
|
8
|
+
class << self
|
9
|
+
# Alias for Yammer::Client.new
|
10
|
+
#
|
11
|
+
# @return [Yammer::Client]
|
12
|
+
def new(options={})
|
13
|
+
Yammer::Client.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Delegate to Yammer::Client
|
17
|
+
def method_missing(method, *args, &block)
|
18
|
+
return super unless new.respond_to?(method)
|
19
|
+
new.send(method, *args, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def respond_to?(method, include_private = false)
|
23
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/yammer/api.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'yammer/authentication'
|
2
|
+
require 'yammer/configuration'
|
3
|
+
require 'yammer/connection'
|
4
|
+
require 'yammer/request'
|
5
|
+
|
6
|
+
module Yammer
|
7
|
+
# @private
|
8
|
+
class API
|
9
|
+
include Connection
|
10
|
+
include Request
|
11
|
+
include Authentication
|
12
|
+
|
13
|
+
# @private
|
14
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
15
|
+
|
16
|
+
# Creates a new API
|
17
|
+
def initialize(options={})
|
18
|
+
options = Yammer.options.merge(options)
|
19
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
20
|
+
send("#{key}=", options[key])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Yammer
|
2
|
+
# @private
|
3
|
+
module Authentication
|
4
|
+
private
|
5
|
+
|
6
|
+
# Authentication hash
|
7
|
+
#
|
8
|
+
# @return [Hash]
|
9
|
+
def authentication
|
10
|
+
{
|
11
|
+
:consumer_key => consumer_key,
|
12
|
+
:consumer_secret => consumer_secret,
|
13
|
+
:token => oauth_token,
|
14
|
+
:token_secret => oauth_token_secret,
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
# Check whether user is authenticated
|
19
|
+
#
|
20
|
+
# @return [Boolean]
|
21
|
+
def authenticated?
|
22
|
+
authentication.values.all?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Yammer
|
2
|
+
# Wrapper for the Yammer REST API
|
3
|
+
#
|
4
|
+
# @note All methods have been separated into modules and follow the same grouping used in {http://developer.yammer.com/api/ the Yammer API Documentation}.
|
5
|
+
# @note From Yammer: When polling for messages, do not exceed one poll per minute. Clients polling excessively will be blocked. However, you may sometimes need to fetch messages more frequently than once per minute, for example, if a user flips between "following", "sent" and "received" feeds quickly), and this is allowed for a few requests. Do not attempt to decrease message latency in your client by checking for new messages more frequently than once per minute.
|
6
|
+
class Client < API
|
7
|
+
# Require client method modules after initializing the Client class in
|
8
|
+
# order to avoid a superclass mismatch error, allowing those modules to be
|
9
|
+
# Client-namespaced.
|
10
|
+
require 'yammer/client/messages'
|
11
|
+
require 'yammer/client/feed'
|
12
|
+
|
13
|
+
alias :api_endpoint :endpoint
|
14
|
+
|
15
|
+
include Yammer::Client::Messages
|
16
|
+
include Yammer::Client::Feed
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Yammer
|
2
|
+
class Client
|
3
|
+
# Defines methods related to feeds (or viewable messages)
|
4
|
+
module Feed
|
5
|
+
# Returns the 20 most recent messages in this network. Corresponds to the "Company Feed" tab on the website.
|
6
|
+
#
|
7
|
+
# @note Developers should note that a strict rate limit is applied to all API requests, so clients should never poll for new messages more frequently than every 30 seconds to ensure that the user is still able to use the API for posting messages, etc.
|
8
|
+
# @format `:json`, `:xml`
|
9
|
+
# @authenticated true
|
10
|
+
# @rate_limited true
|
11
|
+
# @param options [Hash] A customizable set of options.
|
12
|
+
# @option options [Integer] :older_than Returns only messages older than the message ID specified. This is useful for paginating messages.
|
13
|
+
# @option options [Integer] :newer_than Return only messages newer than the message ID specified. This should always be used when polling for new messages.
|
14
|
+
# @option options [String] :threaded Accepts true or extended. When true, will only return the first message in each thread. This parameter is intended for applications which display message threads collapsed. threaded=extended will return the thread starter messages in order of most recently active as well as the two most recent messages, as they are viewed in the default view on our website.
|
15
|
+
# @option options [Integer] :limit Return only the specified number of messages. Works for `threaded=true` and `threaded=extended`.
|
16
|
+
# @return [Hashie::Mash]
|
17
|
+
# @see http://developer.yammer.com/api/#message-viewing
|
18
|
+
# @example Return the 20 most recent messages in this network.
|
19
|
+
# Yammer.messages
|
20
|
+
def messages(options={})
|
21
|
+
response = get('messages', options)
|
22
|
+
format.to_s.downcase == 'xml' ? response['response']['messages'] : response
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the 20 sent messages by the current logged in user.
|
26
|
+
# Alias for `/api/v1/messages/from_user/logged-in_user_id.format`. Corresponds to the "Sent" tab on the website.
|
27
|
+
#
|
28
|
+
# @note Important to note that the XML format returns a different structure than the JSON one. So we only support the JSON format for this method.
|
29
|
+
# @format `:json`
|
30
|
+
# @authenticated true
|
31
|
+
# @rate_limited true
|
32
|
+
# @param options [Hash] A customizable set of options.
|
33
|
+
# @option options [Integer] :older_than Returns only messages older than the message ID specified. This is useful for paginating messages.
|
34
|
+
# @option options [Integer] :newer_than Return only messages newer than the message ID specified. This should always be used when polling for new messages.
|
35
|
+
# @option options [String] :threaded Accepts true or extended. When true, will only return the first message in each thread. This parameter is intended for applications which display message threads collapsed. threaded=extended will return the thread starter messages in order of most recently active as well as the two most recent messages, as they are viewed in the default view on our website.
|
36
|
+
# @option options [Integer] :limit Return only the specified number of messages. Works for `threaded=true` and `threaded=extended`.
|
37
|
+
# @return [Hashie::Mash]
|
38
|
+
# @see http://developer.yammer.com/api/#message-viewing
|
39
|
+
# @example Return the 20 most recent sent messages
|
40
|
+
# Yammer.messages_sent
|
41
|
+
def messages_sent(options={})
|
42
|
+
response = get('messages/sent', options, :json)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Messages received by the logged-in user. Corresponds to the "Received" tab on the website.
|
46
|
+
#
|
47
|
+
# @note Important to note that the XML format returns a different structure than the JSON one. So we only support the JSON format for this method.
|
48
|
+
# @format `:json`
|
49
|
+
# @authenticated true
|
50
|
+
# @rate_limited true
|
51
|
+
# @param options [Hash] A customizable set of options.
|
52
|
+
# @option options [Integer] :older_than Returns only messages older than the message ID specified. This is useful for paginating messages.
|
53
|
+
# @option options [Integer] :newer_than Return only messages newer than the message ID specified. This should always be used when polling for new messages.
|
54
|
+
# @option options [String] :threaded Accepts true or extended. When true, will only return the first message in each thread. This parameter is intended for applications which display message threads collapsed. threaded=extended will return the thread starter messages in order of most recently active as well as the two most recent messages, as they are viewed in the default view on our website.
|
55
|
+
# @option options [Integer] :limit Return only the specified number of messages. Works for `threaded=true` and `threaded=extended`.
|
56
|
+
# @return [Hashie::Mash]
|
57
|
+
# @see http://developer.yammer.com/api/#message-viewing
|
58
|
+
# @example Return the 20 most recent received messages
|
59
|
+
# Yammer.messages_received
|
60
|
+
def messages_received(options={})
|
61
|
+
response = get('messages/received', options, :json)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Private Messages (aka Direct Messages) for the logged-in user. Corresponds to the "Direct Messages" section on the website.
|
65
|
+
#
|
66
|
+
# @note Important to note that the XML format returns a different structure than the JSON one. So we only support the JSON format for this method.
|
67
|
+
# @format `:json`
|
68
|
+
# @authenticated true
|
69
|
+
# @rate_limited true
|
70
|
+
# @param options [Hash] A customizable set of options.
|
71
|
+
# @option options [Integer] :older_than Returns only messages older than the message ID specified. This is useful for paginating messages.
|
72
|
+
# @option options [Integer] :newer_than Return only messages newer than the message ID specified. This should always be used when polling for new messages.
|
73
|
+
# @option options [String] :threaded Accepts true or extended. When true, will only return the first message in each thread. This parameter is intended for applications which display message threads collapsed. threaded=extended will return the thread starter messages in order of most recently active as well as the two most recent messages, as they are viewed in the default view on our website.
|
74
|
+
# @option options [Integer] :limit Return only the specified number of messages. Works for `threaded=true` and `threaded=extended`.
|
75
|
+
# @return [Hashie::Mash]
|
76
|
+
# @see http://developer.yammer.com/api/#message-viewing
|
77
|
+
# @example Return the 20 most recent private messages
|
78
|
+
# Yammer.direct_messages
|
79
|
+
def direct_messages(options={})
|
80
|
+
response = get('messages/private', options, :json)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Messages followed by the logged-in user. Corresponds to the "My Feed" tab on the website.
|
84
|
+
#
|
85
|
+
# @note Important to note that the XML format returns a different structure than the JSON one. So we only support the JSON format for this method.
|
86
|
+
# @format `:json`
|
87
|
+
# @authenticated true
|
88
|
+
# @rate_limited true
|
89
|
+
# @param options [Hash] A customizable set of options.
|
90
|
+
# @option options [Integer] :older_than Returns only messages older than the message ID specified. This is useful for paginating messages.
|
91
|
+
# @option options [Integer] :newer_than Return only messages newer than the message ID specified. This should always be used when polling for new messages.
|
92
|
+
# @option options [String] :threaded Accepts true or extended. When true, will only return the first message in each thread. This parameter is intended for applications which display message threads collapsed. threaded=extended will return the thread starter messages in order of most recently active as well as the two most recent messages, as they are viewed in the default view on our website.
|
93
|
+
# @option options [Integer] :limit Return only the specified number of messages. Works for `threaded=true` and `threaded=extended`.
|
94
|
+
# @return [Hashie::Mash]
|
95
|
+
# @see http://developer.yammer.com/api/#message-viewing
|
96
|
+
# @example Return the 20 most recent received messages in my feed
|
97
|
+
# Yammer.my_feed
|
98
|
+
def my_feed(options={})
|
99
|
+
response = get('messages/following', options, :json)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Messages sent by the user with the given ID. Corresponds to the messages on a user profile page on the website.
|
103
|
+
#
|
104
|
+
# @note Important to note that the XML format returns a different structure than the JSON one. So we only support the JSON format for this method.
|
105
|
+
# @format `:json`
|
106
|
+
# @authenticated true
|
107
|
+
# @rate_limited true
|
108
|
+
# @param id [Integer, String] A user ID or screen name.
|
109
|
+
# @param options [Hash] A customizable set of options.
|
110
|
+
# @option options [Integer] :older_than Returns only messages older than the message ID specified. This is useful for paginating messages.
|
111
|
+
# @option options [Integer] :newer_than Return only messages newer than the message ID specified. This should always be used when polling for new messages.
|
112
|
+
# @option options [String] :threaded Accepts true or extended. When true, will only return the first message in each thread. This parameter is intended for applications which display message threads collapsed. threaded=extended will return the thread starter messages in order of most recently active as well as the two most recent messages, as they are viewed in the default view on our website.
|
113
|
+
# @option options [Integer] :limit Return only the specified number of messages. Works for `threaded=true` and `threaded=extended`.
|
114
|
+
# @return [Hashie::Mash]
|
115
|
+
# @see http://developer.yammer.com/api/#message-viewing
|
116
|
+
# @example Return the 20 most recent messages from the user
|
117
|
+
# Yammer.messages_from("bruno")
|
118
|
+
def messages_from(id, options={})
|
119
|
+
response = get("messages/from_user/#{id}", options, :json)
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Yammer
|
2
|
+
class Client
|
3
|
+
# Defines methods related to manipulating messages
|
4
|
+
module Messages
|
5
|
+
# Creates a new message from the authenticating user
|
6
|
+
#
|
7
|
+
# @note A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.
|
8
|
+
# @format `:json`, `:xml`
|
9
|
+
# @authenticated true
|
10
|
+
# @rate_limited false
|
11
|
+
# @param body [String] The text of your message.
|
12
|
+
# @param options [Hash] A customizable set of options.
|
13
|
+
# @option options [Integer] :in_reply_to_message_id The ID of an existing message that the message is in reply to.
|
14
|
+
# @option options [Integer] :group_id The ID of the group in which this message belongs.
|
15
|
+
# @option options [Integer] :replied_to_id The message ID this message is in reply to, if applicable.
|
16
|
+
# @option options [Integer] :direct_to_id the ID of the user to which this message will be sent as a private message.
|
17
|
+
# @option options [String] :broadcast If `true` this message should be broadcasted to all users. *Must be an admin*
|
18
|
+
# @option options [Integer] :topic*n* Topics to apply to the message. Can use topic1 through topic20.
|
19
|
+
# @return [Hashie::Mash] The created message.
|
20
|
+
# @see http://developer.yammer.com/api/#messages-manipulating
|
21
|
+
# @example Creates a new message for the authenticating user
|
22
|
+
# Yammer.update("I just posted a status update via the Yammer Ruby Gem!")
|
23
|
+
def update(message, options={})
|
24
|
+
response = post('messages', options.merge(:body => message))
|
25
|
+
format.to_s.downcase == 'xml' ? response['response']['messages'] : response
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'yammer/version'
|
2
|
+
|
3
|
+
module Yammer
|
4
|
+
# Defines constants and methods related to configuration
|
5
|
+
module Configuration
|
6
|
+
# An array of valid keys in the options hash when configuring a {Yammer::API}
|
7
|
+
VALID_OPTIONS_KEYS = [
|
8
|
+
:adapter,
|
9
|
+
:consumer_key,
|
10
|
+
:consumer_secret,
|
11
|
+
:endpoint,
|
12
|
+
:format,
|
13
|
+
:gateway,
|
14
|
+
:oauth_token,
|
15
|
+
:oauth_token_secret,
|
16
|
+
:proxy,
|
17
|
+
:user_agent].freeze
|
18
|
+
|
19
|
+
# The adapter that will be used to connect if none is set
|
20
|
+
DEFAULT_ADAPTER = :net_http
|
21
|
+
|
22
|
+
# By default, don't set an application key
|
23
|
+
DEFAULT_CONSUMER_KEY = nil
|
24
|
+
|
25
|
+
# By default, don't set an application secret
|
26
|
+
DEFAULT_CONSUMER_SECRET = nil
|
27
|
+
|
28
|
+
# The endpoint that will be used to connect if none is set
|
29
|
+
#
|
30
|
+
# @note This is configurable in case you want to use HTTP instead of HTTPS, specify a different API version.
|
31
|
+
DEFAULT_ENDPOINT = 'https://www.yammer.com/api/v1/'.freeze
|
32
|
+
|
33
|
+
# The response format appended to the path and sent in the 'Accept' header if none is set
|
34
|
+
#
|
35
|
+
# @note JSON is preferred over XML because it is more concise and faster to parse.
|
36
|
+
DEFAULT_FORMAT = :json
|
37
|
+
|
38
|
+
# By default, don't set a user oauth token
|
39
|
+
DEFAULT_OAUTH_TOKEN = nil
|
40
|
+
|
41
|
+
# By default, don't set a user oauth secret
|
42
|
+
DEFAULT_OAUTH_TOKEN_SECRET = nil
|
43
|
+
|
44
|
+
# By default, don't use a proxy server
|
45
|
+
DEFAULT_PROXY = nil
|
46
|
+
|
47
|
+
# The value sent in the 'User-Agent' header if none is set
|
48
|
+
DEFAULT_USER_AGENT = "Yammer Ruby Gem #{Yammer::VERSION}".freeze
|
49
|
+
|
50
|
+
DEFAULT_GATEWAY = nil
|
51
|
+
|
52
|
+
# @private
|
53
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
54
|
+
|
55
|
+
# When this module is extended, set all configuration options to their default values
|
56
|
+
def self.extended(base)
|
57
|
+
base.reset
|
58
|
+
end
|
59
|
+
|
60
|
+
# Convenience method to allow configuration options to be set in a block
|
61
|
+
def configure
|
62
|
+
yield self
|
63
|
+
end
|
64
|
+
|
65
|
+
# Create a hash of options and their values
|
66
|
+
def options
|
67
|
+
options = {}
|
68
|
+
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
|
69
|
+
options
|
70
|
+
end
|
71
|
+
|
72
|
+
# Reset all configuration options to defaults
|
73
|
+
def reset
|
74
|
+
self.adapter = DEFAULT_ADAPTER
|
75
|
+
self.consumer_key = DEFAULT_CONSUMER_KEY
|
76
|
+
self.consumer_secret = DEFAULT_CONSUMER_SECRET
|
77
|
+
self.endpoint = DEFAULT_ENDPOINT
|
78
|
+
self.format = DEFAULT_FORMAT
|
79
|
+
self.oauth_token = DEFAULT_OAUTH_TOKEN
|
80
|
+
self.oauth_token_secret = DEFAULT_OAUTH_TOKEN_SECRET
|
81
|
+
self.proxy = DEFAULT_PROXY
|
82
|
+
self.user_agent = DEFAULT_USER_AGENT
|
83
|
+
self.gateway = DEFAULT_GATEWAY
|
84
|
+
self
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
require 'faraday/request/multipart_with_file'
|
3
|
+
require 'faraday/request/gateway'
|
4
|
+
require 'faraday/request/yammer_oauth'
|
5
|
+
require 'faraday/response/raise_http_4xx'
|
6
|
+
require 'faraday/response/raise_http_5xx'
|
7
|
+
|
8
|
+
module Yammer
|
9
|
+
# @private
|
10
|
+
module Connection
|
11
|
+
private
|
12
|
+
|
13
|
+
def connection(format=format)
|
14
|
+
options = {
|
15
|
+
:headers => {
|
16
|
+
:accept => "application/#{format}",
|
17
|
+
:user_agent => user_agent,
|
18
|
+
},
|
19
|
+
:proxy => proxy,
|
20
|
+
:ssl => {:verify => false},
|
21
|
+
:url => api_endpoint,
|
22
|
+
}
|
23
|
+
|
24
|
+
Faraday.new(options) do |builder|
|
25
|
+
builder.use Faraday::Request::MultipartWithFile
|
26
|
+
builder.use Faraday::Request::YammerOAuth, authentication if authenticated?
|
27
|
+
builder.use Faraday::Request::Multipart
|
28
|
+
builder.use Faraday::Request::UrlEncoded
|
29
|
+
builder.use Faraday::Request::Gateway, gateway if gateway
|
30
|
+
builder.use Faraday::Response::RaiseHttp4xx
|
31
|
+
case format.to_s.downcase
|
32
|
+
when 'json'
|
33
|
+
builder.use Faraday::Response::Mashify
|
34
|
+
builder.use Faraday::Response::ParseJson
|
35
|
+
when 'xml'
|
36
|
+
builder.use Faraday::Response::Mashify
|
37
|
+
builder.use Faraday::Response::ParseXml
|
38
|
+
end
|
39
|
+
builder.use Faraday::Response::RaiseHttp5xx
|
40
|
+
builder.adapter(adapter)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/yammer/error.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Yammer
|
2
|
+
# Custom error class for rescuing from all Yammer errors
|
3
|
+
class Error < StandardError
|
4
|
+
attr_reader :http_headers
|
5
|
+
|
6
|
+
def initialize(message, http_headers)
|
7
|
+
@http_headers = Hash[http_headers]
|
8
|
+
super message
|
9
|
+
end
|
10
|
+
|
11
|
+
def ratelimit_reset
|
12
|
+
Time.at(@http_headers.values_at('x-ratelimit-reset', 'X-RateLimit-Reset').detect{|value| value}.to_i)
|
13
|
+
end
|
14
|
+
|
15
|
+
def ratelimit_limit
|
16
|
+
@http_headers.values_at('x-ratelimit-limit', 'X-RateLimit-Limit').detect{|value| value}.to_i
|
17
|
+
end
|
18
|
+
|
19
|
+
def ratelimit_remaining
|
20
|
+
@http_headers.values_at('x-ratelimit-remaining', 'X-RateLimit-Remaining').detect{|value| value}.to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
def retry_after
|
24
|
+
[(ratelimit_reset - Time.now).ceil, 0].max
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Raised when Yammer returns the HTTP status code 400
|
29
|
+
class BadRequest < Error; end
|
30
|
+
|
31
|
+
# Raised when Yammer returns the HTTP status code 401
|
32
|
+
class Unauthorized < Error; end
|
33
|
+
|
34
|
+
# Raised when Yammer returns the HTTP status code 403
|
35
|
+
class Forbidden < Error; end
|
36
|
+
|
37
|
+
# Raised when Yammer returns the HTTP status code 404
|
38
|
+
class NotFound < Error; end
|
39
|
+
|
40
|
+
# Raised when Yammer returns the HTTP status code 406
|
41
|
+
class NotAcceptable < Error; end
|
42
|
+
|
43
|
+
# Raised when Yammer returns the HTTP status code 500
|
44
|
+
class InternalServerError < Error; end
|
45
|
+
|
46
|
+
# Raised when Yammer returns the HTTP status code 502
|
47
|
+
class BadGateway < Error; end
|
48
|
+
|
49
|
+
# Raised when Yammer returns the HTTP status code 503
|
50
|
+
class ServiceUnavailable < Error; end
|
51
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Yammer
|
2
|
+
# Defines HTTP request methods
|
3
|
+
module Request
|
4
|
+
# Perform an HTTP GET request
|
5
|
+
def get(path, options={}, format=format)
|
6
|
+
request(:get, path, options, format)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Perform an HTTP POST request
|
10
|
+
def post(path, options={}, format=format)
|
11
|
+
request(:post, path, options, format)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Perform an HTTP PUT request
|
15
|
+
def put(path, options={}, format=format)
|
16
|
+
request(:put, path, options, format)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Perform an HTTP DELETE request
|
20
|
+
def delete(path, options={}, format=format)
|
21
|
+
request(:delete, path, options, format)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# Perform an HTTP request
|
27
|
+
def request(method, path, options, format)
|
28
|
+
response = connection(format).send(method) do |request|
|
29
|
+
case method.to_sym
|
30
|
+
when :get, :delete
|
31
|
+
request.url(formatted_path(path, format), options)
|
32
|
+
when :post, :put
|
33
|
+
request.path = formatted_path(path, format)
|
34
|
+
request.body = options unless options.empty?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
'raw' == format.to_s.downcase ? response : response.body
|
38
|
+
end
|
39
|
+
|
40
|
+
def formatted_path(path, format)
|
41
|
+
case format.to_s.downcase
|
42
|
+
when 'json', 'xml'
|
43
|
+
[path, format].compact.join('.')
|
44
|
+
when 'raw'
|
45
|
+
[path, Yammer.format].compact.join('.')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/yammer.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "yammer/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.add_development_dependency 'maruku', '~> 0.6'
|
7
|
+
gem.add_development_dependency 'nokogiri', '~> 1.4'
|
8
|
+
gem.add_development_dependency 'rake', '~> 0.9'
|
9
|
+
gem.add_development_dependency 'rspec', '~> 2.6'
|
10
|
+
gem.add_development_dependency 'simplecov', '~> 0.4'
|
11
|
+
gem.add_development_dependency 'webmock', '~> 1.6'
|
12
|
+
gem.add_development_dependency 'yard', '~> 0.7'
|
13
|
+
gem.add_development_dependency 'ZenTest', '~> 4.5'
|
14
|
+
gem.add_runtime_dependency 'hashie', '~> 1.0.0'
|
15
|
+
gem.add_runtime_dependency 'faraday', '~> 0.6.1'
|
16
|
+
gem.add_runtime_dependency 'faraday_middleware', '~> 0.6.3'
|
17
|
+
gem.add_runtime_dependency 'multi_json', '~> 1.0.0'
|
18
|
+
gem.add_runtime_dependency 'multi_xml', '~> 0.2.0'
|
19
|
+
gem.add_runtime_dependency 'simple_oauth', '~> 0.1.5'
|
20
|
+
gem.authors = ["Bruno Mattarollo"]
|
21
|
+
gem.description = %q{A Ruby wrapper for the Yammer REST API}
|
22
|
+
gem.email = ['bruno.mattarollo@gmail.com']
|
23
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
24
|
+
gem.files = `git ls-files`.split("\n")
|
25
|
+
gem.homepage = 'https://github.com/roadly/yammer'
|
26
|
+
gem.name = 'yammer'
|
27
|
+
gem.require_paths = ['lib']
|
28
|
+
gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
|
29
|
+
gem.summary = %q{Ruby wrapper for the Yammer API}
|
30
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
31
|
+
gem.version = Yammer::VERSION.dup
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yammer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bruno Mattarollo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-07-09 00:00:00.000000000 +10:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: maruku
|
17
|
+
requirement: &2160287980 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.6'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2160287980
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: nokogiri
|
28
|
+
requirement: &2160287480 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2160287480
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rake
|
39
|
+
requirement: &2160287020 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0.9'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2160287020
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
requirement: &2160356940 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '2.6'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *2160356940
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: simplecov
|
61
|
+
requirement: &2160356480 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0.4'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *2160356480
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: webmock
|
72
|
+
requirement: &2160356020 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.6'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *2160356020
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: yard
|
83
|
+
requirement: &2160355560 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0.7'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *2160355560
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: ZenTest
|
94
|
+
requirement: &2160355100 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ~>
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '4.5'
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *2160355100
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: hashie
|
105
|
+
requirement: &2160354640 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.0.0
|
111
|
+
type: :runtime
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: *2160354640
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: faraday
|
116
|
+
requirement: &2160354180 !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ~>
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 0.6.1
|
122
|
+
type: :runtime
|
123
|
+
prerelease: false
|
124
|
+
version_requirements: *2160354180
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: faraday_middleware
|
127
|
+
requirement: &2160353720 !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ~>
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 0.6.3
|
133
|
+
type: :runtime
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: *2160353720
|
136
|
+
- !ruby/object:Gem::Dependency
|
137
|
+
name: multi_json
|
138
|
+
requirement: &2160353260 !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ~>
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: 1.0.0
|
144
|
+
type: :runtime
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: *2160353260
|
147
|
+
- !ruby/object:Gem::Dependency
|
148
|
+
name: multi_xml
|
149
|
+
requirement: &2160352800 !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ~>
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: 0.2.0
|
155
|
+
type: :runtime
|
156
|
+
prerelease: false
|
157
|
+
version_requirements: *2160352800
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: simple_oauth
|
160
|
+
requirement: &2160352340 !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ~>
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 0.1.5
|
166
|
+
type: :runtime
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: *2160352340
|
169
|
+
description: A Ruby wrapper for the Yammer REST API
|
170
|
+
email:
|
171
|
+
- bruno.mattarollo@gmail.com
|
172
|
+
executables: []
|
173
|
+
extensions: []
|
174
|
+
extra_rdoc_files: []
|
175
|
+
files:
|
176
|
+
- .gitignore
|
177
|
+
- .yardopts
|
178
|
+
- Gemfile
|
179
|
+
- HISTORY.md
|
180
|
+
- LICENSE.md
|
181
|
+
- README.md
|
182
|
+
- Rakefile
|
183
|
+
- lib/faraday/request/gateway.rb
|
184
|
+
- lib/faraday/request/multipart_with_file.rb
|
185
|
+
- lib/faraday/request/yammer_oauth.rb
|
186
|
+
- lib/faraday/response/raise_http_4xx.rb
|
187
|
+
- lib/faraday/response/raise_http_5xx.rb
|
188
|
+
- lib/yammer.rb
|
189
|
+
- lib/yammer/api.rb
|
190
|
+
- lib/yammer/authentication.rb
|
191
|
+
- lib/yammer/client.rb
|
192
|
+
- lib/yammer/client/feed.rb
|
193
|
+
- lib/yammer/client/messages.rb
|
194
|
+
- lib/yammer/configuration.rb
|
195
|
+
- lib/yammer/connection.rb
|
196
|
+
- lib/yammer/error.rb
|
197
|
+
- lib/yammer/request.rb
|
198
|
+
- lib/yammer/version.rb
|
199
|
+
- yammer.gemspec
|
200
|
+
has_rdoc: true
|
201
|
+
homepage: https://github.com/roadly/yammer
|
202
|
+
licenses: []
|
203
|
+
post_install_message:
|
204
|
+
rdoc_options: []
|
205
|
+
require_paths:
|
206
|
+
- lib
|
207
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
208
|
+
none: false
|
209
|
+
requirements:
|
210
|
+
- - ! '>='
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
213
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
214
|
+
none: false
|
215
|
+
requirements:
|
216
|
+
- - ! '>='
|
217
|
+
- !ruby/object:Gem::Version
|
218
|
+
version: 1.3.6
|
219
|
+
requirements: []
|
220
|
+
rubyforge_project:
|
221
|
+
rubygems_version: 1.6.2
|
222
|
+
signing_key:
|
223
|
+
specification_version: 3
|
224
|
+
summary: Ruby wrapper for the Yammer API
|
225
|
+
test_files: []
|