yam 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/bundle
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - 1.8.7
6
+ - ree
@@ -0,0 +1,90 @@
1
+ Contributing
2
+ ============
3
+
4
+
5
+ Quick Overview
6
+ --------------
7
+
8
+ We love pull requests. Here's a quick overview of the process (detail below):
9
+
10
+ 1. Fork the repo.
11
+
12
+ 2. Run the tests. We only take pull requests with passing tests, so start with a clean slate.
13
+
14
+ 3. Add a test for your new code. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, we need a test!
15
+
16
+ 4. Make the test pass.
17
+
18
+ 5. Push to your fork and submit a pull request.
19
+
20
+ At this point you're waiting on us. We may suggest some changes or improvements or alternatives. Once we approve, we will merge your branch in.
21
+
22
+ Some things that will increase the chance that your pull request is accepted, taken straight from the Ruby on Rails guide:
23
+
24
+ * Use Rails idioms and helpers
25
+ * Include tests which fail without your code and pass with it
26
+ * Update the documentation, the surrounding code, examples elsewhere, guides, whatever is affected by your contribution
27
+
28
+
29
+ Requirements
30
+ --------------
31
+
32
+ Please remember this is open-source, so don't commit any passwords or API keys.
33
+ Those should go in config variables like `ENV['API_KEY']`.
34
+
35
+
36
+ Laptop setup
37
+ ------------
38
+
39
+ Fork the repo and clone the app:
40
+
41
+ git clone git@github.com:[GIT_USERNAME]/yam.git
42
+
43
+
44
+ Install Bundler 1.2.0.pre or higher:
45
+
46
+ gem install bundler --pre
47
+
48
+ Set up the app:
49
+
50
+ cd yam
51
+ bundle --binstubs
52
+
53
+
54
+ Running tests
55
+ -------------
56
+
57
+ Run the whole test suite with:
58
+
59
+ rake
60
+
61
+ Run individual specs like:
62
+
63
+ rspec spec/yam_spec.rb
64
+
65
+ Tab complete to make it even faster!
66
+
67
+ When a spec file has many specs, you sometimes want to run just what you're
68
+ working on. In that case, specify a line number:
69
+
70
+ rspec spec/yam_spec.rb:9
71
+
72
+
73
+ Syntax
74
+ ------
75
+
76
+ * Two spaces, no tabs.
77
+ * No trailing whitespace. Blank lines should not have any spaces.
78
+ * Prefer `&&/||` over `and/or`.
79
+ * `MyClass.my_method(my_arg)` not `my_method( my_arg )` or `my_method my_arg`.
80
+ * `a = b` and not `a=b`.
81
+ * Follow the conventions you see used in the source already.
82
+
83
+ And in case we didn't emphasize it enough: we love tests!
84
+
85
+
86
+ Development process
87
+ -------------------
88
+
89
+ For details and screenshots of the feature branch code review process,
90
+ read [this blog post](http://robots.thoughtbot.com/post/2831837714/feature-branch-code-reviews).
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yam.gemspec
4
+ gemspec
@@ -0,0 +1,16 @@
1
+ Copyright (c) Microsoft Corporation
2
+ All rights reserved.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+
15
+ See the Apache Version 2.0 License for specific language governing
16
+ permissions and limitations under the License.
@@ -0,0 +1,144 @@
1
+ Yam
2
+ ===
3
+
4
+ The official Yammer Ruby gem.
5
+
6
+ NOTE: Currently in alpha - use at your own risk
7
+
8
+ Installation
9
+ ------------
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'yam'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```sh
20
+ $ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```sh
26
+ $ gem install yam
27
+ ```
28
+
29
+ General Configuration
30
+ ---------------------
31
+
32
+ The Yammer API requires you to authenticate via OAuth, so you'll need to register your Yammer application. To register a new application, sign in to Yammer and then fill out the form at https://www.yammer.com/client_applications.
33
+
34
+ If you already have your access token, you can skip this section.
35
+
36
+ To retrieve your access token, follow these steps.
37
+
38
+ 1. Construct the following URL using the client_id you received after registering your app with Yammer: <https://www.yammer.com/dialog/oauth?client_id=[:client_id]>
39
+
40
+ 2. Follow the URL you constructed above. It will take you to a Yammer OAuth dialog. Click the "Allow" button.
41
+
42
+ 3. You will be redirected to a URL that looks something like this: <http://[:redirect_uri]?code=[:code]>
43
+
44
+ 4. Use the code from step 3 along with your client_id and client_secret (obtained when registering your app) to construct the following URL:
45
+ <https://www.yammer.com/oauth2/access_token.json?client_id=[:client_id]&client_secret=[:client_secret]&code=[:code]>
46
+
47
+ 5. The authorization server will return an access token object as part of a broader response that includes user profile information.
48
+
49
+ Sample access token (token is 'abcdefghijklmn' in this example) as part of response:
50
+
51
+ ```
52
+ “access_token”: {
53
+ “view_subscriptions”: true,
54
+ “expires_at”: null,
55
+ authorized_at”: “2011/04/06 16:25:46 +0000”,
56
+ “modify_subscriptions”: true,
57
+ “modify_messages”: true,
58
+ “network_permalink”: “yammer-inc.com”,
59
+ “view_members”: true,
60
+ “view_tags”: true,
61
+ “network_id”: 155465488,
62
+ “user_id”: 1014216,
63
+ “view_groups”: true,
64
+ “token”: “abcdefghijklmn”,
65
+ “network_name”: “Yammer”,
66
+ “view_messages”: true,
67
+ “created_at”: “2011/04/06 16:25:46 +0000”
68
+ }
69
+ ```
70
+
71
+ Set the OAuth token on your app. Example:
72
+
73
+ ```ruby
74
+ Yam.configure do |config|
75
+ config.oauth_token = your_oauth_token
76
+ end
77
+ ```
78
+
79
+ Rails Configuration
80
+ -------------------
81
+
82
+ Retrieve your access token using the steps outlined in the <a href="#general-configuration">general configuration</a> section above.
83
+
84
+ Add the following to a `yammer.rb` file in your `config/initializers` directory:
85
+
86
+ ```ruby
87
+ Yam.configure do |config|
88
+ config.oauth_token = oauth_token
89
+ end
90
+ ```
91
+
92
+ Set up Yammer OAuth 2.0
93
+ -----------------------
94
+
95
+ See Yammer's Developer Guide for step-by-step instructions on setting up OAuth 2.0: <http://developer.yammer.com/files/2012/10/PlatformDeveloperGuide.pdf>
96
+
97
+ Usage Examples
98
+ --------------
99
+
100
+ All examples require an authenticated Yammer client. See the <a
101
+ href="#general-configuration">general configuration</a> section for instructions for finding and setting your access token.
102
+
103
+ For a list of all Yammer API endpoints, see the <a href="http://developer.yammer.com/restapi/">REST API documentation</a>.
104
+
105
+ **Find a Yammer user by email**
106
+
107
+ ```ruby
108
+ Yam.get('/users/by_email', email: 'user@example.com')
109
+ ```
110
+
111
+ **Find a Yammer user by the Yammer user id**
112
+
113
+ ```ruby
114
+ Yam.get('/users/123456')
115
+ ```
116
+
117
+ **Post a status update from the current user**
118
+
119
+ ```ruby
120
+ Yam.post('/messages', body: 'status update')
121
+ ```
122
+
123
+ **Send a private message to another Yammer user**
124
+
125
+ ```ruby
126
+ Yam.post('/messages', body: 'this is a private message', direct_to_id: 123456)
127
+ ```
128
+
129
+ **Send a private message to a Yammer group**
130
+
131
+ ```ruby
132
+ Yam.post('/messages', body: 'this is a group message', group_id: 987654)
133
+ ```
134
+
135
+ **Send a message with an Open Graph Object as an attachment**
136
+
137
+ ```ruby
138
+ Yam.post('/messages', :body: 'here is my open graph object', og_url: "https://www.yammer.com/example/graph/123456789")
139
+ ```
140
+
141
+ Contributing
142
+ ------------
143
+
144
+ To contribute to this project, see the [CONTRIBUTING.md](https://github.com/yammer/yam/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,23 @@
1
+ # Copyright (c) Microsoft Corporation
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ # PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ #
15
+ # See the Apache Version 2.0 License for specific language governing
16
+ # permissions and limitations under the License.
17
+ #
18
+ require 'bundler/gem_tasks'
19
+ require 'rspec/core/rake_task'
20
+
21
+ RSpec::Core::RakeTask.new(:spec)
22
+
23
+ task :default => :spec
data/lib/yam.rb CHANGED
@@ -1 +1,44 @@
1
+ # Copyright (c) Microsoft Corporation
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ # PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ #
15
+ # See the Apache Version 2.0 License for specific language governing
16
+ # permissions and limitations under the License.
17
+
1
18
  require 'yam/version'
19
+ require 'yam/configuration'
20
+ require 'yam/client'
21
+
22
+ module Yam
23
+ extend Configuration
24
+
25
+ class << self
26
+ # Handler for the client instance
27
+ attr_accessor :api_client
28
+
29
+ # Alias for Yam::Client.new
30
+ def new(options = {}, &block)
31
+ @api_client = Yam::Client.new(options, &block)
32
+ end
33
+
34
+ # Delegate to Yam::Client
35
+ def method_missing(method, *args, &block)
36
+ return super unless new.respond_to?(method)
37
+ new.send(method, *args, &block)
38
+ end
39
+
40
+ def respond_to?(method, include_private = false)
41
+ new.respond_to?(method, include_private) || super(method, include_private)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,56 @@
1
+ # Copyright (c) Microsoft Corporation
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ # PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ #
15
+ # See the Apache Version 2.0 License for specific language governing
16
+ # permissions and limitations under the License.
17
+ #
18
+
19
+ # API setup and configuration
20
+ require 'yam/request'
21
+ require 'yam/connection'
22
+ require 'yam/configuration'
23
+
24
+ module Yam
25
+ class API
26
+ include Connection
27
+ include Request
28
+ attr_reader *Configuration::VALID_OPTIONS_KEYS
29
+
30
+ class_eval do
31
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
32
+ define_method "#{key}=" do |arg|
33
+ self.instance_variable_set("@#{key}", arg)
34
+ Yam.send("#{key}=", arg)
35
+ end
36
+ end
37
+ end
38
+
39
+ def initialize(options={}, &block)
40
+ setup(options)
41
+ end
42
+
43
+ def setup(options={})
44
+ options = Yam.options.merge(options)
45
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
46
+ send("#{key}=", options[key])
47
+ end
48
+ end
49
+
50
+ def method_missing(method, *args, &block)
51
+ if method.to_s.match /^(.*)\?$/
52
+ return !self.send($1.to_s).nil?
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,23 @@
1
+ # Copyright (c) Microsoft Corporation
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ # PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ #
15
+ # See the Apache Version 2.0 License for specific language governing
16
+ # permissions and limitations under the License.
17
+ #
18
+ require 'yam/api'
19
+
20
+ module Yam
21
+ class Client < API
22
+ end
23
+ end
@@ -0,0 +1,59 @@
1
+ # Copyright (c) Microsoft Corporation
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ # PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ #
15
+ # See the Apache Version 2.0 License for specific language governing
16
+ # permissions and limitations under the License.
17
+
18
+ module Yam
19
+ module Configuration
20
+ VALID_OPTIONS_KEYS = [
21
+ :adapter,
22
+ :endpoint,
23
+ :oauth_token,
24
+ :user_agent,
25
+ ].freeze
26
+
27
+ DEFAULT_ADAPTER = :net_http
28
+
29
+ DEFAULT_ENDPOINT = 'https://www.yammer.com/api/v1'.freeze
30
+
31
+ DEFAULT_OAUTH_TOKEN = nil
32
+
33
+ DEFAULT_USER_AGENT = "Yam Ruby Gem #{Yam::VERSION}".freeze
34
+
35
+ attr_accessor *VALID_OPTIONS_KEYS
36
+
37
+ def configure
38
+ yield self
39
+ end
40
+
41
+ def self.extended(base)
42
+ base.set_defaults
43
+ end
44
+
45
+ def options
46
+ options = {}
47
+ VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
48
+ options
49
+ end
50
+
51
+ def set_defaults
52
+ self.adapter = DEFAULT_ADAPTER
53
+ self.endpoint = DEFAULT_ENDPOINT
54
+ self.oauth_token = DEFAULT_OAUTH_TOKEN
55
+ self.user_agent = DEFAULT_USER_AGENT
56
+ self
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,62 @@
1
+ # Copyright (c) Microsoft Corporation
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ # PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ #
15
+ # See the Apache Version 2.0 License for specific language governing
16
+ # permissions and limitations under the License.
17
+ #
18
+ require 'faraday'
19
+ require 'yam/constants'
20
+ require 'faraday_middleware/response/mashify'
21
+ require 'faraday_middleware/response/parse_json'
22
+ require 'faraday_middleware/request/oauth2'
23
+
24
+ module Yam
25
+ module Connection
26
+ extend self
27
+ include Yam::Constants
28
+
29
+ def default_options(options={})
30
+ {
31
+ :headers => {
32
+ ACCEPT => 'application/json',
33
+ ACCEPT_CHARSET => 'utf-8',
34
+ USER_AGENT => user_agent
35
+ },
36
+ :ssl => { :verify => true },
37
+ :url => options.fetch(:endpoint) { Yam.endpoint }
38
+ }.merge(options)
39
+ end
40
+
41
+ # Returns a Faraday::Connection object
42
+ #
43
+ def connection(options = {})
44
+ conn_options = default_options(options)
45
+ clear_cache unless options.empty?
46
+ puts "OPTIONS:#{conn_options.inspect}" if ENV['DEBUG']
47
+
48
+ @connection ||= Faraday.new(conn_options) do |conn|
49
+ conn.use Faraday::Response::Mashify
50
+ conn.use FaradayMiddleware::ParseJson
51
+ conn.response :raise_error
52
+
53
+ if oauth_token?
54
+ conn.use FaradayMiddleware::OAuth2, oauth_token
55
+ end
56
+
57
+ conn.request :url_encoded
58
+ conn.adapter adapter
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,28 @@
1
+ # Copyright (c) Microsoft Corporation
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ # PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ #
15
+ # See the Apache Version 2.0 License for specific language governing
16
+ # permissions and limitations under the License.
17
+ #
18
+ module Yam
19
+ module Constants
20
+ extend self
21
+
22
+ USER_AGENT = 'User-Agent'.freeze
23
+
24
+ ACCEPT = 'Accept'.freeze
25
+
26
+ ACCEPT_CHARSET = 'Accept-Charset'.freeze
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ # Copyright (c) Microsoft Corporation
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ # PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ #
15
+ # See the Apache Version 2.0 License for specific language governing
16
+ # permissions and limitations under the License.
17
+ #
18
+
19
+ # Defines HTTP verbs
20
+ module Yam
21
+ module Request
22
+ def get(path, params={}, options={})
23
+ request(:get, path, params, options)
24
+ end
25
+
26
+ def post(path, params={}, options={})
27
+ request(:post, path, params, options)
28
+ end
29
+
30
+ def request(method, path, params, options)
31
+ conn = connection(options)
32
+ path = (conn.path_prefix + path).gsub(/\/\//,'/') if conn.path_prefix != '/'
33
+
34
+ response = conn.send(method,path,params)
35
+ response.body
36
+ end
37
+ end
38
+ end
@@ -1,4 +1,20 @@
1
+ # Copyright (c) Microsoft Corporation
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ # PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ #
15
+ # See the Apache Version 2.0 License for specific language governing
16
+ # permissions and limitations under the License.
17
+
1
18
  module Yam
2
- VERSION = '0.0.1'
3
- LOCATION = File.dirname __FILE__ # :nodoc:
19
+ VERSION = '0.0.2'
4
20
  end
@@ -0,0 +1,59 @@
1
+ # Copyright (c) Microsoft Corporation
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ # PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ #
15
+ # See the Apache Version 2.0 License for specific language governing
16
+ # permissions and limitations under the License.
17
+ #
18
+ require 'simplecov'
19
+ SimpleCov.start do
20
+ add_filter 'spec'
21
+ end
22
+ require 'rspec'
23
+ require 'yam'
24
+ require 'webmock/rspec'
25
+ require 'bourne'
26
+
27
+ RSpec.configure do |config|
28
+ config.mock_with :mocha
29
+ config.include WebMock::API
30
+ config.order = :rand
31
+ config.color_enabled = true
32
+ config.before(:each) do
33
+ Yam.set_defaults
34
+ end
35
+ end
36
+
37
+ def stub_post(path, endpoint = Yam.endpoint.to_s)
38
+ stub_request(:post, endpoint + path)
39
+ end
40
+
41
+ def stub_get(path, endpoint = Yam.endpoint.to_s)
42
+ stub_request(:get, endpoint + path)
43
+ end
44
+
45
+ def a_post(path, endpoint = Yam.endpoint.to_s)
46
+ a_request(:post, endpoint + path)
47
+ end
48
+
49
+ def a_get(path, endpoint = Yam.endpoint.to_s)
50
+ a_request(:get, endpoint + path)
51
+ end
52
+
53
+ def fixture_path
54
+ File.expand_path("../fixtures", __FILE__)
55
+ end
56
+
57
+ def fixture(file)
58
+ File.new(File.join(fixture_path, '/', file))
59
+ end
@@ -0,0 +1,42 @@
1
+ # Copyright (c) Microsoft Corporation
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ # PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ #
15
+ # See the Apache Version 2.0 License for specific language governing
16
+ # permissions and limitations under the License.
17
+ #
18
+ require 'spec_helper'
19
+
20
+ describe Yam::Client, '#get' do
21
+ it 'makes requests' do
22
+ stub_get('/custom/get')
23
+ subject.get('/custom/get')
24
+ expect(a_get('/custom/get')).to have_been_made
25
+ end
26
+ end
27
+
28
+ describe Yam::Client, '#post' do
29
+ it 'makes requests' do
30
+ stub_post('/custom/post')
31
+ subject.post('/custom/post')
32
+ expect(a_post('/custom/post')).to have_been_made
33
+ end
34
+
35
+ it 'makes authorized requests' do
36
+ access_token = '123'
37
+ Yam.oauth_token = access_token
38
+ stub_post("/custom/post?access_token=#{access_token}")
39
+ subject.post('/custom/post')
40
+ expect(a_post("/custom/post?access_token=#{access_token}")).to have_been_made
41
+ end
42
+ end
@@ -0,0 +1,100 @@
1
+ # Copyright (c) Microsoft Corporation
2
+ # All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
12
+ # IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR
13
+ # PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
14
+ #
15
+ # See the Apache Version 2.0 License for specific language governing
16
+ # permissions and limitations under the License.
17
+ #
18
+ require 'spec_helper'
19
+ class TestClass
20
+ end
21
+ describe Yam do
22
+
23
+ after do
24
+ subject.set_defaults
25
+ end
26
+
27
+ it 'responds to \'new\' message' do
28
+ subject.should respond_to :new
29
+ end
30
+
31
+ it 'receives \'new\' and initialize subject::Client instance' do
32
+ subject.new.should be_a Yam::Client
33
+ end
34
+
35
+ it 'delegates to a Yam::Client instance' do
36
+ Yam::Client.any_instance.stubs(:stubbed_method)
37
+
38
+ Yam.stubbed_method
39
+
40
+ Yam::Client.any_instance.should have_received(:stubbed_method)
41
+ end
42
+
43
+ it 'responds to \'configure\' message' do
44
+ subject.should respond_to :configure
45
+ end
46
+
47
+ describe 'setting configuration options' do
48
+ it 'returns the default adapter' do
49
+ subject.adapter.should == Yam::Configuration::DEFAULT_ADAPTER
50
+ end
51
+
52
+ it 'allows setting the adapter' do
53
+ subject.adapter = :typhoeus
54
+ subject.adapter.should == :typhoeus
55
+ end
56
+
57
+ it 'returns the default end point' do
58
+ subject.endpoint.should == Yam::Configuration::DEFAULT_ENDPOINT
59
+ end
60
+
61
+ it 'allows setting the endpoint' do
62
+ subject.endpoint = 'http://www.example.com'
63
+ subject.endpoint.should == 'http://www.example.com'
64
+ end
65
+
66
+ it 'returns the default user agent' do
67
+ subject.user_agent.should == Yam::Configuration::DEFAULT_USER_AGENT
68
+ end
69
+
70
+ it 'allows setting the user agent' do
71
+ subject.user_agent = 'New User Agent'
72
+ subject.user_agent.should == 'New User Agent'
73
+ end
74
+
75
+ it 'does not set oauth token' do
76
+ subject.oauth_token.should be_nil
77
+ end
78
+
79
+ it 'does not allow setting the oauth token' do
80
+ subject.oauth_token = 'OT'
81
+ subject.oauth_token.should == 'OT'
82
+ end
83
+
84
+ it 'allows setting the current api client' do
85
+ subject.should respond_to :api_client=
86
+ subject.should respond_to :api_client
87
+ end
88
+ end
89
+
90
+ describe '.configure' do
91
+ Yam::Configuration::VALID_OPTIONS_KEYS.each do |key|
92
+ it "should set the #{key}" do
93
+ Yam.configure do |config|
94
+ config.send("#{key}=", key)
95
+ Yam.send(key).should == key
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -1,22 +1,32 @@
1
- require 'lib/yam/version'
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
4
 
3
- Gem::Specification.new do |gem|
4
- gem.name = 'yam'
5
- gem.version = Yam::VERSION
5
+ require 'yam/version'
6
6
 
7
- gem.author, gem.email = 'Jordi Bunster', 'jbunster@yammer-inc.com'
7
+ Gem::Specification.new do |gem|
8
+ gem.name = 'yam'
9
+ gem.version = Yam::VERSION
10
+ gem.authors = ['Mason Fischer', 'Jessie A. Young']
11
+ gem.email = ['mason@thoughtbot.com', 'jessie@apprentice.io']
12
+ gem.description = %q{The official Yammer Ruby gem.}
13
+ gem.summary = %q{A Ruby wrapper for the Yammer REST API}
14
+ gem.homepage = %q{https://github.com/yammer/yam}
8
15
 
9
- gem.summary = "Placeholder for Yammer's Ruby API"
10
- gem.description = "Placeholder for Yammer's Ruby API"
11
- gem.required_ruby_version = '>= 1.8.7'
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ['lib']
12
20
 
13
- gem.has_rdoc = false
21
+ gem.add_dependency 'hashie', '~> 1.2.0'
22
+ gem.add_dependency 'faraday', '~> 0.8.1'
23
+ gem.add_dependency 'faraday_middleware', '~> 0.9.0'
24
+ gem.add_dependency 'multi_json', '~> 1.3'
25
+ gem.add_dependency 'oauth2', '~> 0.8.0'
14
26
 
15
- gem.files = %w[
16
- lib
17
- lib/yam
18
- lib/yam/version.rb
19
- lib/yam.rb
20
- yam.gemspec
21
- ]
27
+ gem.add_development_dependency 'rspec'
28
+ gem.add_development_dependency 'simplecov', '~> 0.7.1'
29
+ gem.add_development_dependency 'mocha', '~> 0.9.8'
30
+ gem.add_development_dependency 'bourne', '~> 1.0'
31
+ gem.add_development_dependency 'webmock', '~> 1.9.0'
22
32
  end
metadata CHANGED
@@ -1,57 +1,229 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: yam
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
- - Jordi Bunster
7
+ authors:
8
+ - Mason Fischer
9
+ - Jessie A. Young
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
-
12
- date: 2011-07-15 00:00:00 -07:00
13
- default_executable:
14
- dependencies: []
15
-
16
- description: Placeholder for Yammer's Ruby API
17
- email: jbunster@yammer-inc.com
13
+ date: 2012-12-12 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hashie
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.2.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 1.2.0
31
+ - !ruby/object:Gem::Dependency
32
+ name: faraday
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 0.8.1
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 0.8.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: faraday_middleware
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 0.9.0
63
+ - !ruby/object:Gem::Dependency
64
+ name: multi_json
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '1.3'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '1.3'
79
+ - !ruby/object:Gem::Dependency
80
+ name: oauth2
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: 0.8.0
87
+ type: :runtime
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 0.8.0
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: 0.7.1
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ~>
125
+ - !ruby/object:Gem::Version
126
+ version: 0.7.1
127
+ - !ruby/object:Gem::Dependency
128
+ name: mocha
129
+ requirement: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ~>
133
+ - !ruby/object:Gem::Version
134
+ version: 0.9.8
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ~>
141
+ - !ruby/object:Gem::Version
142
+ version: 0.9.8
143
+ - !ruby/object:Gem::Dependency
144
+ name: bourne
145
+ requirement: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ~>
149
+ - !ruby/object:Gem::Version
150
+ version: '1.0'
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ~>
157
+ - !ruby/object:Gem::Version
158
+ version: '1.0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: webmock
161
+ requirement: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: 1.9.0
167
+ type: :development
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ~>
173
+ - !ruby/object:Gem::Version
174
+ version: 1.9.0
175
+ description: The official Yammer Ruby gem.
176
+ email:
177
+ - mason@thoughtbot.com
178
+ - jessie@apprentice.io
18
179
  executables: []
19
-
20
180
  extensions: []
21
-
22
181
  extra_rdoc_files: []
23
-
24
- files:
25
- - lib/yam/version.rb
182
+ files:
183
+ - .gitignore
184
+ - .travis.yml
185
+ - CONTRIBUTING.md
186
+ - Gemfile
187
+ - LICENSE.txt
188
+ - README.md
189
+ - Rakefile
26
190
  - lib/yam.rb
191
+ - lib/yam/api.rb
192
+ - lib/yam/client.rb
193
+ - lib/yam/configuration.rb
194
+ - lib/yam/connection.rb
195
+ - lib/yam/constants.rb
196
+ - lib/yam/request.rb
197
+ - lib/yam/version.rb
198
+ - spec/spec_helper.rb
199
+ - spec/yam/client_spec.rb
200
+ - spec/yam_spec.rb
27
201
  - yam.gemspec
28
- has_rdoc: true
29
- homepage:
202
+ homepage: https://github.com/yammer/yam
30
203
  licenses: []
31
-
32
204
  post_install_message:
33
205
  rdoc_options: []
34
-
35
- require_paths:
206
+ require_paths:
36
207
  - lib
37
- required_ruby_version: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: 1.8.7
42
- version:
43
- required_rubygems_version: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: "0"
48
- version:
208
+ required_ruby_version: !ruby/object:Gem::Requirement
209
+ none: false
210
+ requirements:
211
+ - - ! '>='
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ required_rubygems_version: !ruby/object:Gem::Requirement
215
+ none: false
216
+ requirements:
217
+ - - ! '>='
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
49
220
  requirements: []
50
-
51
221
  rubyforge_project:
52
- rubygems_version: 1.3.5
222
+ rubygems_version: 1.8.24
53
223
  signing_key:
54
224
  specification_version: 3
55
- summary: Placeholder for Yammer's Ruby API
56
- test_files: []
57
-
225
+ summary: A Ruby wrapper for the Yammer REST API
226
+ test_files:
227
+ - spec/spec_helper.rb
228
+ - spec/yam/client_spec.rb
229
+ - spec/yam_spec.rb