yapper 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODRmNDFlYTYzZGYzZDJjNzU4NDQwYTg0YWM4YmVhYTA3OGQ2ZGMyMg==
5
+ data.tar.gz: !binary |-
6
+ YWQ4NjY0NTMxNDQyOGQ2NDdhZDhlYjExOWVkNTkxMmVjN2IwNmI1ZA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NjkwZjA3YTk3ZjEzNzY1YTJmYmQyM2Y5YWIyMWQ3NjYyODdmOTg0Mzg3NTFl
10
+ OTkzNjM3NzZiYmQ0ZTllYmY4NmZjMzlkZjBiZjJmNTY4NjFmZjM0NGJmYjNh
11
+ NDg1NzdkMjJhNWQ5MjFlNzBmYzc4ODA1NjNlMDkwNzljYmM3ZDk=
12
+ data.tar.gz: !binary |-
13
+ ZmNmNzIwZDU3MWQ4YTNhZDdhZDI2YzU0NTZjZmMxN2E1NjhiNzEzNTQzMWU1
14
+ OTA3ZmUyOTNhZjI4NTNjMDQ1Zjc5YjY2OGRhZDM4ZjljMDA4YzBkODg0MTUz
15
+ NWY5YzVlYTY0OTk5N2RmNDgyYjYyNDhlY2NmMzhhZDc0N2M5ZTc=
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,49 @@
1
+ 0.1.7 - December 26th, 2013
2
+ ----------------
3
+
4
+ * [synth](https://github.com/synth) Renames Yammer gem to Yapper
5
+ * [synth](https://github.com/synth) Updates the dependency on Yam gem to latest: 2.1.1
6
+
7
+ 0.1.4
8
+ ----------------
9
+
10
+ This release rips out the old api dependencies on Faraday and whatever else handles connection related issues and passed it all off to Yammer's own Yam gem(which itself uses Faraday).
11
+
12
+ Improved api support
13
+
14
+ yam.users
15
+ yam.in_group
16
+
17
+ Better Exception Handling
18
+
19
+ It was completely broken, now you can catch all sorts of exceptions with Yammer api based upon http status:
20
+
21
+ - 400: Yammer::BadRequest
22
+ - 401: Yammer::Unauthorized
23
+ - 403: Yammer::Forbidden
24
+ - 404: Yammer::NotFound
25
+ - 406: Yammer::NotAcceptable
26
+ - 500: Yammer:InternalServerError
27
+ - 502: Yammer::BadGateway
28
+ - 503: Yammer::ServiceUnavailable
29
+
30
+ 0.1.2 - April 19th, 2012
31
+ -------------------------
32
+ * [ybenjo](https://github.com/ybenjo) added search, groups and suggestions api support.
33
+
34
+ 0.1.1 - Sept 21st, 2011
35
+ -------------------------
36
+ * [Rob Warner](https://github.com/hoop33) added about_topic and user[:id]
37
+
38
+ 0.1.0 - July 15th, 2011
39
+ -------------------------
40
+ * First public release
41
+ * Basic README.md
42
+
43
+ 0.0.2 - July 9th, 2011
44
+ -------------------------
45
+ * Adding support for messages in threads
46
+
47
+ 0.0.1 - July 9th, 2011
48
+ -------------------------
49
+ * [Initial release](http://github.com/roadly/yammer)
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2011, Peter Philips
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
+
@@ -0,0 +1,90 @@
1
+ The Yammer Ruby Gem
2
+ ====================
3
+ A Ruby wrapper for the Yammer REST APIs
4
+
5
+ This was originally forked from http://github.com/roadly/yammer. I had to rename it due to namespace collisions with the latest Yam gem(which really users Yammer modules)
6
+
7
+ Installation
8
+ ------------
9
+ gem install yapper
10
+
11
+ What's new in 0.1.7?
12
+ ----------------
13
+
14
+ Renames Yammer gem to Yapper
15
+ Updates the dependency on Yam gem to latest: 2.1.1
16
+
17
+ See HISTORY.md for more
18
+
19
+
20
+ Getting Started
21
+ ---------------
22
+
23
+ You should probably be using Omniauth(http://github.com/intridea/omniauth), cuz its awesome, and be following that flow. Ryan Bate's excellent RailsCasts are also a great reference: http://railscasts.com/episodes/236-omniauth-part-2
24
+
25
+ Whatever controller handles the callback, you will have access to a "credentials" key in the oauth object which has an "expires" key, and a "token" key. I stash that entire object in a serialized string in my Authentication model. This token is what you will need.
26
+
27
+ token = current_user.authentications.find_by_provider("yammer").credentials.token
28
+ yam = Yammer.new(oauth_token: token)
29
+
30
+ That's it!
31
+
32
+ yam.groups
33
+ yam.users
34
+
35
+
36
+ TODO
37
+ ----
38
+
39
+ * Specs, specs and specs ... we lack tests even basic ones.
40
+ * Support for the following APIs
41
+ * Likes
42
+ * Topics
43
+ * Users
44
+ * Group Memberships
45
+ * Networks
46
+
47
+ Contributing
48
+ ------------
49
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
50
+
51
+ Here are some ways *you* can contribute:
52
+
53
+ * by using alpha, beta, and prerelease versions
54
+ * by reporting bugs
55
+ * by suggesting new features
56
+ * by writing or editing documentation
57
+ * by writing tests
58
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
59
+ * by refactoring code
60
+ * by closing [issues](https://github.com/roadly/yammer/issues)
61
+ * by reviewing patches
62
+
63
+ All contributors will be added to the [HISTORY](https://github.com/roadly/yammer/blob/master/HISTORY.md)
64
+ file and will receive the respect and gratitude of the community.
65
+
66
+ Submitting an Issue
67
+ -------------------
68
+ We use the [GitHub issue tracker](https://github.com/roadly/yammer/issues) to track bugs and
69
+ features. Before submitting a bug report or feature request, check to make sure it hasn't already
70
+ been submitted. You can indicate support for an existing issue by voting it up. When submitting a
71
+ bug report, please include a [Gist](https://gist.github.com/) that includes a stack trace and any
72
+ details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
73
+ operating system.
74
+
75
+ Submitting a Pull Request
76
+ -------------------------
77
+ 1. Fork the project.
78
+ 2. Create a topic branch.
79
+ 3. Implement your feature or bug fix.
80
+ 4. Add documentation for your feature or bug fix.
81
+ 5. Run <tt>bundle exec rake doc:yard</tt>. If your changes are not 100% documented, go back to step 4.
82
+ 6. Commit and push your changes.
83
+ 7. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
84
+
85
+
86
+
87
+ Copyright
88
+ ---------
89
+ Copyright (c) 2011, Peter Philips <pete <-at-> p373.net>
90
+ See [LICENSE](https://github.com/roadly/yammer/blob/master/LICENSE.md) for details.
@@ -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
@@ -0,0 +1,27 @@
1
+ require 'yammer'
2
+ require 'yapper/api'
3
+ require 'yapper/client'
4
+ require 'yapper/configuration'
5
+ require 'yapper/error'
6
+
7
+ module Yapper
8
+ extend Configuration
9
+ class << self
10
+ # Alias for Yapper::Client.new
11
+ #
12
+ # @return [Yapper::Client]
13
+ def new(options={})
14
+ Yapper::Client.new(options)
15
+ end
16
+
17
+ # Delegate to Yammer::Client
18
+ def method_missing(method, *args, &block)
19
+ return super unless new.respond_to?(method)
20
+ new.send(method, *args, &block)
21
+ end
22
+
23
+ def respond_to?(method, include_private = false)
24
+ new.respond_to?(method, include_private) || super(method, include_private)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ require 'yapper/authentication'
2
+ require 'yapper/configuration'
3
+ require 'yapper/connection'
4
+ require 'yapper/request'
5
+
6
+ module Yapper
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 = Yapper.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,23 @@
1
+ module Yapper
2
+ # @private
3
+ module Authentication
4
+ # Check whether user is authenticated
5
+ #
6
+ # @return [Boolean]
7
+ def authenticated?
8
+ authentication.values.all?
9
+ end
10
+
11
+ private
12
+
13
+ # Authentication hash
14
+ #
15
+ # @return [Hash]
16
+ def authentication
17
+ {
18
+ oauth_token: oauth_token
19
+ }
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ module Yapper
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 'yapper/client/messages'
11
+ require 'yapper/client/feed'
12
+ require 'yapper/client/users'
13
+ require 'yapper/client/search'
14
+ require 'yapper/client/suggestions'
15
+ require 'yapper/client/groups'
16
+ require 'yapper/client/activity'
17
+
18
+ alias :api_endpoint :endpoint
19
+
20
+ include Yapper::Client::Messages
21
+ include Yapper::Client::Feed
22
+ include Yapper::Client::Users
23
+ include Yapper::Client::Search
24
+ include Yapper::Client::Suggestions
25
+ include Yapper::Client::Groups
26
+ include Yapper::Client::Activity
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ module Yapper
2
+ class Client
3
+ module Activity
4
+ def new_activity(options={})
5
+ response = post('activity', options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,163 @@
1
+ module Yapper
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
+ # Messages that have the topic with given ID. Corresponds to the messages on a topic's page on the website.
123
+ #
124
+ # @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.
125
+ # @format `:json`
126
+ # @authenticated true
127
+ # @rate_limited true
128
+ # @param id [Integer] A topic ID
129
+ # @param options [Hash] A customizable set of options.
130
+ # @option options [Integer] :older_than Returns only messages older than the message ID specified. This is useful for paginating messages.
131
+ # @option options [Integer] :newer_than Return only messages newer than the message ID specified. This should always be used when polling for new messages.
132
+ # @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.
133
+ # @option options [Integer] :limit Return only the specified number of messages. Works for `threaded=true` and `threaded=extended`.
134
+ # @return [Hashie::Mash]
135
+ # @see http://developer.yammer.com/api/#message-viewing
136
+ # @example Return the messages in topic with ID 1234567
137
+ # Yammer.about_topic(1234567)
138
+ def about_topic(id, options={})
139
+ response = get("messages/about_topic/#{id}", options, :json)
140
+ end
141
+
142
+ # Messages in the thread with the given ID. Corresponds to the page you'd see when clicking on "in reply to" on the website.
143
+ #
144
+ # @note Does not accept the threaded parameter.
145
+ # @format `:json`
146
+ # @authenticated true
147
+ # @rate_limited true
148
+ # @param id [Integer] A thread ID
149
+ # @param options [Hash] A customizable set of options.
150
+ # @option options [Integer] :older_than Returns only messages older than the message ID specified. This is useful for paginating messages.
151
+ # @option options [Integer] :newer_than Return only messages newer than the message ID specified. This should always be used when polling for new messages.
152
+ # @option options [Integer] :limit Return only the specified number of messages. Works for `threaded=true` and `threaded=extended`.
153
+ # @return [Hashie::Mash]
154
+ # @see http://developer.yammer.com/api/#message-viewing
155
+ # @example Return the messages in the thread with ID 1234567
156
+ # Yammer.thread(1234567)
157
+ def thread(id, options={})
158
+ response = get("messages/in_thread/#{id}", options)
159
+ format.to_s.downcase == 'xml' ? response['response']['messages'] : response
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,44 @@
1
+ module Yapper
2
+ class Client
3
+ # Defines methods related to groups
4
+ module Groups
5
+ # Get groups information.
6
+ # @see https://developer.yammer.com/api/#groups
7
+ #
8
+ # @format `:json`
9
+ # @authenticated true
10
+ # @rate_limited unconfirmed
11
+ # @param options [Hash] A customizable set of options.
12
+ # @option options [Integer] :page 20 groups will be shown per page.
13
+ # @option options [String] :letter Return groups beginning with the given letter.
14
+ # @option options [messages|members|privacy|created_at|creator] :sort_by Results will be returned sorted by one of the above options instead of the default behavior of sorting by number of messages.
15
+ # @option options [String] :reverse Return results in reverse order if uses true.
16
+ # @option options [String] :private Used when creating or updating groups to make them private if uses true.
17
+ # @return [Hashie::Mash] Informations of groups.
18
+ def groups(options={})
19
+ get("groups", options)
20
+ end
21
+
22
+ # Get specific group information.
23
+ #
24
+ # @format `:json`
25
+ # @authenticated true
26
+ # @rate_limited unconfirmed
27
+ # @param id [Integer] The id of specific group.
28
+ # @return [Hashie::Mash] Informations of group which id is #{id}.
29
+ def group(id, options={})
30
+ get("groups/#{id}", options)
31
+ end
32
+
33
+ # Create/Update group.
34
+ #
35
+ # @authenticated true
36
+ # @rate_limited unconfirmed
37
+ # @param name [String] The name of group.
38
+ # @param private [String] Used true when creating or updating groups to make them private.
39
+ def create_group(name, options={})
40
+ post('groups', options.merge({:name => name}))
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ module Yapper
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,24 @@
1
+ module Yapper
2
+ class Client
3
+ # Defines methods related to search
4
+ module Search
5
+ # Returns the 20 lists of messages, users, tags and groups that match the user's search query.
6
+ #
7
+ # @format `:json`
8
+ # @authenticated true
9
+ # @rate_limited ***
10
+ # @param query [String] The search query.
11
+ # @param options [Hash] A customizable set of options.
12
+ # @option options [Integer] :page Only 20 results of each type will be returned for each page, but a total count is returned with each query. page=1 (the default) will return items 1-20, page=2 will return items 21-30, etc.
13
+ # @option options [Integer] :num_per_page limit of search results, up to a maximum of 20, the default value.
14
+ # @return [Hashie::Mash]
15
+ # @see https://developer.yammer.com/api/#search
16
+ # @example
17
+ # Yammer.search("my boss")
18
+ def search(query, options={})
19
+ get('search', options.merge({:search => query}))
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,29 @@
1
+ module Yapper
2
+ class Client
3
+ # Defines methods to get/declines suggestions.
4
+ module Suggestions
5
+ # Return suggested groups and users.
6
+ #
7
+ # @format `:json`
8
+ # @authenticated true
9
+ # @rate_limited
10
+ # @param options [Hash] A customizable set of options.
11
+ # @option options [Integer] :limit Returns only Return only the specified number of suggestions.
12
+ # @return [Hashie::Mash]
13
+ # @see https://developer.yammer.com/api/#suggestions
14
+ # @example
15
+ # Yammer.suggestions
16
+ def suggestions(options={})
17
+ get('suggestions', options)
18
+ end
19
+
20
+ # Decline a suggestion specfic id.
21
+ # @param id [Integer/String] When declining a suggestion, pass its id.
22
+ # @example
23
+ # Yammer.decline_suggestion(12345)
24
+ def decline_suggestion(id)
25
+ delete("suggestions/#{id}")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ module Yapper
2
+ class Client
3
+ # Defines methods related to manipulating users
4
+ module Users
5
+ def find_by_id(id, options={})
6
+ response = get("users/#{id}", options, :json)
7
+ end
8
+
9
+ def users(options={})
10
+ response = get("users", options, :json)
11
+ end
12
+
13
+ def in_group(group_id, options={})
14
+ response = get("users/in_group/#{group_id}", options, :json)
15
+ end
16
+
17
+ def current(options={})
18
+ response = get("users/current", options, :json)
19
+ end
20
+
21
+ def followers(name, options={})
22
+ response = get("users/following/#{name}", options, :json)
23
+ end
24
+
25
+ def following(email, options={})
26
+ response = get("users/by_email?email=#{email}", options, :json)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,78 @@
1
+ require 'yammer/version'
2
+
3
+ module Yapper
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
+ :endpoint,
10
+ :api_path_prefix,
11
+ :format,
12
+ :gateway,
13
+ :oauth_token,
14
+ :proxy,
15
+ :user_agent].freeze
16
+
17
+ # The adapter that will be used to connect if none is set
18
+ DEFAULT_ADAPTER = :net_http
19
+
20
+ # The endpoint that will be used to connect if none is set
21
+ #
22
+ # @note This is configurable in case you want to use HTTP instead of HTTPS, specify a different API version.
23
+ DEFAULT_ENDPOINT = 'https://www.yammer.com/'.freeze
24
+
25
+ DEFAULT_API_VERSION = 'v1'.freeze
26
+
27
+ DEFAULT_API_PATH_PREFIX = 'api/'+DEFAULT_API_VERSION
28
+
29
+ # The response format appended to the path and sent in the 'Accept' header if none is set
30
+ #
31
+ # @note JSON is preferred over XML because it is more concise and faster to parse.
32
+ DEFAULT_FORMAT = :json
33
+
34
+ # By default, don't set a user oauth token
35
+ DEFAULT_OAUTH_TOKEN = nil
36
+
37
+ # By default, don't use a proxy server
38
+ DEFAULT_PROXY = nil
39
+
40
+ # The value sent in the 'User-Agent' header if none is set
41
+ DEFAULT_USER_AGENT = "Yammer Ruby Gem #{Yapper::VERSION}".freeze
42
+
43
+ DEFAULT_GATEWAY = nil
44
+
45
+ # @private
46
+ attr_accessor *VALID_OPTIONS_KEYS
47
+
48
+ # When this module is extended, set all configuration options to their default values
49
+ def self.extended(base)
50
+ base.reset
51
+ end
52
+
53
+ # Convenience method to allow configuration options to be set in a block
54
+ def configure
55
+ yield self
56
+ end
57
+
58
+ # Create a hash of options and their values
59
+ def options
60
+ options = {}
61
+ VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
62
+ options
63
+ end
64
+
65
+ # Reset all configuration options to defaults
66
+ def reset
67
+ self.adapter = DEFAULT_ADAPTER
68
+ self.endpoint = DEFAULT_ENDPOINT
69
+ self.api_path_prefix = DEFAULT_API_PATH_PREFIX
70
+ self.format = DEFAULT_FORMAT
71
+ self.oauth_token = DEFAULT_OAUTH_TOKEN
72
+ self.proxy = DEFAULT_PROXY
73
+ self.user_agent = DEFAULT_USER_AGENT
74
+ self.gateway = DEFAULT_GATEWAY
75
+ self
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,10 @@
1
+ module Yapper
2
+ # @private
3
+ module Connection
4
+ private
5
+
6
+ def connection(format=format)
7
+ Yammer::Client.new(access_token: oauth_token, endpoint: endpoint)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,102 @@
1
+ module Yapper
2
+
3
+ # This gem seems to monkey patch faraday to catch certain exceptions
4
+ # and even that attempt does not seem to be loaded anywhere, so instead
5
+ # we'll catch the error on every request(and possibly elsewhere)
6
+ # and then pass the exception to this class who will figure out the proper
7
+ # high level exception to raise
8
+ class ErrorProxy
9
+ def self.new(exception)
10
+ return self.determine_exception(exception)
11
+ end
12
+
13
+ def self.determine_exception(exception)
14
+ exception = exception
15
+ message = exception.message
16
+ status = exception.response[:status]
17
+ headers = exception.response[:headers]
18
+
19
+ case status.to_i
20
+ when 400
21
+ Yapper::BadRequest.new(error_message(message), headers)
22
+ when 401
23
+ Yapper::Unauthorized.new(error_message(message), headers)
24
+ when 403
25
+ Yapper::Forbidden.new(error_message(message), headers)
26
+ when 404
27
+ Yapper::NotFound.new(error_message(message), headers)
28
+ when 429
29
+ Yapper::TooManyRequests.new(error_message(message), headers)
30
+ when 406
31
+ Yapper::NotAcceptable.new(error_message(message), headers)
32
+ when 500
33
+ Yapper::InternalServerError.new(error_message("Something is technically wrong."), headers)
34
+ when 502
35
+ Yapper::BadGateway.new(error_message("Yammer is down or being upgraded."), headers)
36
+ when 503
37
+ Yapper::ServiceUnavailable.new(error_message("(__-){ Yammer is over capacity."), headers)
38
+ else
39
+ Exception.new("Unhandled Exception Status: #{status} - #{message}")
40
+ end
41
+ end
42
+
43
+ private
44
+ def self.error_message(msg)
45
+ #TODO: this can be used in the future to print nicer messages
46
+ msg
47
+ end
48
+ end
49
+
50
+ # Custom error class for rescuing from all Yammer errors
51
+ class Error < StandardError
52
+ attr_reader :http_headers
53
+
54
+ def initialize(message, http_headers)
55
+ @http_headers = Hash[http_headers]
56
+ super message
57
+ end
58
+
59
+ def ratelimit_reset
60
+ Time.at(@http_headers.values_at('x-ratelimit-reset', 'X-RateLimit-Reset').detect{|value| value}.to_i)
61
+ end
62
+
63
+ def ratelimit_limit
64
+ @http_headers.values_at('x-ratelimit-limit', 'X-RateLimit-Limit').detect{|value| value}.to_i
65
+ end
66
+
67
+ def ratelimit_remaining
68
+ @http_headers.values_at('x-ratelimit-remaining', 'X-RateLimit-Remaining').detect{|value| value}.to_i
69
+ end
70
+
71
+ def retry_after
72
+ [(ratelimit_reset - Time.now).ceil, 0].max
73
+ end
74
+ end
75
+
76
+ # Raised when Yammer returns the HTTP status code 400
77
+ class BadRequest < Error; end
78
+
79
+ # Raised when Yammer returns the HTTP status code 401
80
+ class Unauthorized < Error; end
81
+
82
+ # Raised when Yammer returns the HTTP status code 403
83
+ class Forbidden < Error; end
84
+
85
+ # Raised when Yammer returns the HTTP status code 404
86
+ class NotFound < Error; end
87
+
88
+ # Raised when Yammer returns the HTTP status code 406
89
+ class NotAcceptable < Error; end
90
+
91
+ # Raised when Yammer returns the HTTP status code 500
92
+ class InternalServerError < Error; end
93
+
94
+ # Raised when Yammer returns the HTTP status code 502
95
+ class BadGateway < Error; end
96
+
97
+ # Raised when Yammer returns the HTTP status code 503
98
+ class ServiceUnavailable < Error; end
99
+
100
+ # Raised when you hit Yammer's request rate limit
101
+ class TooManyRequests < Error;end
102
+ end
@@ -0,0 +1,76 @@
1
+ module Yapper
2
+ # Defines HTTP request methods
3
+ module Request
4
+ # Perform an HTTP GET request
5
+ def get(path, options={}, format=format)
6
+ respond request(:get, path, options, format)
7
+ end
8
+
9
+ # Perform an HTTP POST request
10
+ def post(path, options={}, format=format)
11
+ respond request(:post, path, options, format)
12
+ end
13
+
14
+ # Perform an HTTP PUT request
15
+ def put(path, options={}, format=format)
16
+ respond request(:put, path, options, format)
17
+ end
18
+
19
+ # Perform an HTTP DELETE request
20
+ def delete(path, options={}, format=format)
21
+ respond request(:delete, path, options, format)
22
+ end
23
+
24
+ private
25
+
26
+ def respond(raw_response)
27
+ body = raw_response.body
28
+ case body
29
+ when Array
30
+ body.map{|item| Hashie::Mash.new(item)}
31
+ when Hash
32
+ Hashie::Mash.new(body)
33
+ else
34
+ raise "Unhandled response type"
35
+ end
36
+ end
37
+
38
+ # Perform an HTTP request
39
+ def request(method, path, options, format)
40
+ begin
41
+ case method.to_sym
42
+ when :get, :delete
43
+ response = connection.send(method, formatted_path(path, format), options)
44
+ when :post
45
+ response = connection.send(method, formatted_path(path, format), options)
46
+ when :put
47
+ raise "PUT verbs are not yet supported!"
48
+ # request.path = formatted_path(path, format)
49
+ # request.body = options unless options.empty?
50
+ end
51
+
52
+ #TODO: format is not obeyed. From Yam we get back an array of objects
53
+ response
54
+
55
+ rescue MultiJson::DecodeError
56
+ Hashie::Mash.new
57
+ rescue Faraday::Error::ClientError => e
58
+ raise Yapper::ErrorProxy.new(e)
59
+
60
+ end
61
+ end
62
+
63
+ def formatted_path(path, format)
64
+ #paths must have a leading /
65
+ path = "/#{path}" if path[0] != "/"
66
+ path = "/#{api_path_prefix}#{path}"
67
+
68
+ case format.to_s.downcase
69
+ when 'json', 'xml'
70
+ [path, format].compact.join('.')
71
+ when 'raw'
72
+ [path, Yapper.format].compact.join('.')
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,4 @@
1
+ module Yapper
2
+ # The version of the gem
3
+ VERSION = '0.1.7'.freeze unless defined?(::Yapper::VERSION)
4
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "yapper/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.add_runtime_dependency 'yam', '2.0.1'
7
+ gem.authors = ["Bruno Mattarollo, Peter Philips"]
8
+ gem.description = %q{A Ruby wrapper for the Yammer REST API}
9
+ gem.email = ['bruno.mattarollo@gmail.com', 'pete@p373.net']
10
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.homepage = 'https://github.com/synth/yapper'
13
+ gem.name = 'yapper'
14
+ gem.require_paths = ['lib']
15
+ gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
16
+ gem.summary = %q{Ruby wrapper for the Yammer API}
17
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ gem.version = Yapper::VERSION.dup
19
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.7
5
+ platform: ruby
6
+ authors:
7
+ - Bruno Mattarollo, Peter Philips
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yam
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.1
27
+ description: A Ruby wrapper for the Yammer REST API
28
+ email:
29
+ - bruno.mattarollo@gmail.com
30
+ - pete@p373.net
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - Gemfile
36
+ - HISTORY.md
37
+ - LICENSE.md
38
+ - README.md
39
+ - Rakefile
40
+ - lib/faraday/request/gateway.rb
41
+ - lib/faraday/request/multipart_with_file.rb
42
+ - lib/faraday/request/yammer_oauth.rb
43
+ - lib/faraday/response/raise_http_4xx.rb
44
+ - lib/faraday/response/raise_http_5xx.rb
45
+ - lib/yapper.rb
46
+ - lib/yapper/api.rb
47
+ - lib/yapper/authentication.rb
48
+ - lib/yapper/client.rb
49
+ - lib/yapper/client/activity.rb
50
+ - lib/yapper/client/feed.rb
51
+ - lib/yapper/client/groups.rb
52
+ - lib/yapper/client/messages.rb
53
+ - lib/yapper/client/search.rb
54
+ - lib/yapper/client/suggestions.rb
55
+ - lib/yapper/client/users.rb
56
+ - lib/yapper/configuration.rb
57
+ - lib/yapper/connection.rb
58
+ - lib/yapper/error.rb
59
+ - lib/yapper/request.rb
60
+ - lib/yapper/version.rb
61
+ - yapper.gemspec
62
+ homepage: https://github.com/synth/yapper
63
+ licenses: []
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 1.3.6
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.1.5
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Ruby wrapper for the Yammer API
85
+ test_files: []