buffer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +117 -0
- data/Rakefile +2 -0
- data/buffer.gemspec +26 -0
- data/lib/buffer.rb +107 -0
- data/lib/buffer/version.rb +3 -0
- data/spec/buffer_spec.rb +354 -0
- data/spec/fixtures/create_body.txt +1 -0
- data/spec/fixtures/success.json +1 -0
- data/spec/fixtures/user.json +1 -0
- data/spec/helper.rb +43 -0
- metadata +175 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Tom Ashworth
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# Buffer
|
2
|
+
|
3
|
+
Official API wrapper for [Buffer](http://bufferapp.com) covering user & profile management and adding, removing & editing updates, and more planned endpoints. See the [full API Documentation](http://bufferapp.com/developers/api/) for more.
|
4
|
+
|
5
|
+
For a Buffer OmniAuth strategy for authenticating your users with Buffer, see [omniauth-buffer2](/bufferapp/omniauth-buffer2).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'buffer'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install buffer
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Client
|
24
|
+
|
25
|
+
The most basic usage of the wrapper involves creating a `Buffer::Client` and then making requests through that object. Since all requests to the Buffer API require an access token you must have first authorized a Buffer user, or otherwise have an access token. The [Buffer OmniAuth Strategy](http://github.com/bufferapp/omniauth-buffer2) can help with this.
|
26
|
+
|
27
|
+
Use the Client if you just want to have full control over your `get` and `post` requests.
|
28
|
+
|
29
|
+
Creating a new client is simple:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
buffer = Buffer::Client.new access_token
|
33
|
+
```
|
34
|
+
|
35
|
+
### User
|
36
|
+
|
37
|
+
The User object makes working with users easier by providing some useful shortcuts to user information, like `id`, and data, like `profiles`. It provides the all the methods specified in the Client as it inherits from it.
|
38
|
+
|
39
|
+
The User introduces some caching of requests. These are invalidated when a `post` request is made to an endpoint that might affect the data. You can force cache invalidation of one or all endpoints using the `invalidate` method.
|
40
|
+
|
41
|
+
**Note: Currently only `invalidate` is implemented. If you make a POST request that changes a user object you must manually invalidate the cache**.
|
42
|
+
|
43
|
+
Creating a new user:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
user = Buffer::User.new access_token
|
47
|
+
```
|
48
|
+
|
49
|
+
## API
|
50
|
+
|
51
|
+
You can use a client, or any subclass, to make GET & POST requests to the Buffer API. The exposed API methods are `get`, `post` and, the lowest level, `api`.
|
52
|
+
|
53
|
+
#### api
|
54
|
+
|
55
|
+
`api` is the method at the root of the API, handling all requests.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
api (symbol) method, (string) url, (hash, optional) params, (hash or array, optional) data
|
59
|
+
# for example:
|
60
|
+
buffer.api :get, 'user'
|
61
|
+
```
|
62
|
+
|
63
|
+
`method` must be either `:get` or `:post`
|
64
|
+
|
65
|
+
#### get
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
user_data = buffer.get 'user'
|
69
|
+
user_profiles = buffer.get 'profiles'
|
70
|
+
```
|
71
|
+
|
72
|
+
`get` is just a thin layer over `api`, so the above is equivalent to:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
user_data = buffer.api :get, 'user'
|
76
|
+
user_profiles = buffer.api :get, 'profiles'
|
77
|
+
```
|
78
|
+
|
79
|
+
#### `post`
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
user_data = buffer.post 'updates/create', :text => "Hello, world!", :profile_ids => ['123abc456', '789def123']
|
83
|
+
```
|
84
|
+
|
85
|
+
`post` is also a wrapper for `api`, so the above becomes:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
user_data = buffer.api :post, 'updates/create', :text => "Hello, world!", :profile_ids => ['123abc456', '789def123']
|
89
|
+
```
|
90
|
+
|
91
|
+
## User API
|
92
|
+
|
93
|
+
#### `id`, `created_at`...
|
94
|
+
|
95
|
+
The User object allows access to the data from the user endpoint in manner of a normal ruby accessor. This makes accessing user info very easy, like the following:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
user.id
|
99
|
+
user.created_at
|
100
|
+
```
|
101
|
+
|
102
|
+
#### `profiles` **not implemented**
|
103
|
+
|
104
|
+
`profiles` is a helper method that gives you access to the profiles associated with a particular user. It's shorthand for `get 'profiles'` with caching. The
|
105
|
+
|
106
|
+
`profiles` is invalidated by any `post` request made to a child of the `profiles` endpoing, like `/profiles/:id/schedules/update`.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
user.profiles # all a user's profiles
|
110
|
+
user.profiles '123abc456def' # return a profile with a specific id
|
111
|
+
```
|
112
|
+
|
113
|
+
## Todo
|
114
|
+
|
115
|
+
* `user.profiles`
|
116
|
+
* Automatic cache invalidation after post request
|
117
|
+
* Move cache handling to a mixin
|
data/Rakefile
ADDED
data/buffer.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/buffer/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Tom Ashworth"]
|
6
|
+
gem.email = ["tom@phuu.net"]
|
7
|
+
gem.description = "Buffer API wrapper for Ruby"
|
8
|
+
gem.summary = "Buffer API wrapper for Ruby"
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "buffer"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Buffer::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "faraday"
|
19
|
+
gem.add_dependency "multi_json"
|
20
|
+
gem.add_dependency "i18n"
|
21
|
+
gem.add_dependency "active_support"
|
22
|
+
|
23
|
+
gem.add_development_dependency "rspec", "~> 2.7"
|
24
|
+
gem.add_development_dependency "simplecov"
|
25
|
+
gem.add_development_dependency "webmock"
|
26
|
+
end
|
data/lib/buffer.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'buffer/version'
|
2
|
+
require 'faraday'
|
3
|
+
require 'multi_json'
|
4
|
+
require 'addressable/uri'
|
5
|
+
require 'active_support/core_ext'
|
6
|
+
|
7
|
+
module Buffer
|
8
|
+
class Client
|
9
|
+
|
10
|
+
attr_reader :token
|
11
|
+
|
12
|
+
# Initialize a new Buffer::Client
|
13
|
+
#
|
14
|
+
# Also sets up a Faraday connection object
|
15
|
+
#
|
16
|
+
# token - string access token for use with all API requests
|
17
|
+
def initialize(token)
|
18
|
+
if token.kind_of? String
|
19
|
+
@token = token
|
20
|
+
else
|
21
|
+
raise ArgumentError, "token must be a string"
|
22
|
+
end
|
23
|
+
|
24
|
+
@conn = Faraday.new :url => 'https://api.bufferapp.com/1/'
|
25
|
+
@addr = Addressable::URI.new
|
26
|
+
end
|
27
|
+
|
28
|
+
# get is a shorthand method for api :get
|
29
|
+
#
|
30
|
+
# uri - string endpoint uri
|
31
|
+
def get(uri)
|
32
|
+
api :get, uri
|
33
|
+
end
|
34
|
+
|
35
|
+
# post is a shorthand method for api :post
|
36
|
+
#
|
37
|
+
# uri - string endpoint uri
|
38
|
+
# data - hash or array for POST body
|
39
|
+
def post(uri, data = {})
|
40
|
+
api :post, uri, data
|
41
|
+
end
|
42
|
+
|
43
|
+
# api is the root method of the Client, handling all requests.
|
44
|
+
#
|
45
|
+
# type - HTTP verb, :get or :post
|
46
|
+
# url - enpoint uri, with or without .json
|
47
|
+
# data - hash or array of data to be sent in POST body
|
48
|
+
def api(type, uri, data = {})
|
49
|
+
uri << '.json' unless uri =~ /\.json$/
|
50
|
+
res = if type == :get
|
51
|
+
@conn.get uri, :access_token => @token
|
52
|
+
elsif type == :post
|
53
|
+
@conn.post do |req|
|
54
|
+
req.url uri, :access_token => @token
|
55
|
+
req.body = data.to_query
|
56
|
+
end
|
57
|
+
end
|
58
|
+
# Return nil if the body is less that 2 characters long,
|
59
|
+
# ie. '{}' is the minimum valid JSON, or if the decoder
|
60
|
+
# raises an exception when passed mangled JSON
|
61
|
+
begin
|
62
|
+
MultiJson.load res.body if res.body && res.body.length >= 2
|
63
|
+
rescue
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
class User < Client
|
70
|
+
|
71
|
+
def initialize(token)
|
72
|
+
super
|
73
|
+
invalidate
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
# user is a method for handling the cache of the user
|
79
|
+
# data from the Buffer API.
|
80
|
+
#
|
81
|
+
# Returns a hash of user data.
|
82
|
+
def user
|
83
|
+
@cache[:user] ||= get 'user'
|
84
|
+
end
|
85
|
+
|
86
|
+
public
|
87
|
+
|
88
|
+
# invalidate wipes the cache so that future requests
|
89
|
+
# rebuild it from server data
|
90
|
+
def invalidate
|
91
|
+
@cache = {}
|
92
|
+
end
|
93
|
+
|
94
|
+
# method_missing steps in to enable the helper methods
|
95
|
+
# by trying to get a particular key from self.user
|
96
|
+
#
|
97
|
+
# Returns the user data or the result of super
|
98
|
+
def method_missing(method, *args, &block)
|
99
|
+
user[method.to_s] || super
|
100
|
+
end
|
101
|
+
|
102
|
+
def respond_to?(name)
|
103
|
+
user.key_exist? name
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
data/spec/buffer_spec.rb
ADDED
@@ -0,0 +1,354 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Buffer::Client do
|
4
|
+
|
5
|
+
describe 'new' do
|
6
|
+
|
7
|
+
it 'accepts a token' do
|
8
|
+
client = Buffer::Client.new 'some_token'
|
9
|
+
client.token.should eq('some_token')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'rejects an integer token' do
|
13
|
+
lambda { client = Buffer::Client.new 123 }.should raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'rejects an array token' do
|
17
|
+
lambda { client = Buffer::Client.new [123, 'hello'] }.should raise_error
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'rejects an hash token' do
|
21
|
+
lambda { client = Buffer::Client.new :test => 123 }.should raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'api' do
|
27
|
+
|
28
|
+
subject do
|
29
|
+
Buffer::Client.new 'some_token'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'is a method' do
|
33
|
+
subject.respond_to?(:api).should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'api :get' do
|
37
|
+
|
38
|
+
before do
|
39
|
+
stub_get('user.json').
|
40
|
+
with(:query => {:access_token => 'some_token'}).
|
41
|
+
to_return(
|
42
|
+
:body => fixture('user.json'),
|
43
|
+
:headers => {:content_type => 'application/json; charset=utf-8'})
|
44
|
+
|
45
|
+
stub_get('non_existent.json').
|
46
|
+
with(:query => {:access_token => 'some_token'}).
|
47
|
+
to_return(
|
48
|
+
:body => '',
|
49
|
+
:headers => {:content_type => 'application/json; charset=utf-8'})
|
50
|
+
|
51
|
+
stub_get('mangled.json').
|
52
|
+
with(:query => {:access_token => 'some_token'}).
|
53
|
+
to_return(
|
54
|
+
:body => '{dfpl:[}233]',
|
55
|
+
:headers => {:content_type => 'application/json; charset=utf-8'})
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'makes correct request to user.json with access token' do
|
59
|
+
subject.api :get, 'user.json'
|
60
|
+
a_get('user.json').
|
61
|
+
with(:query => {:access_token => 'some_token'}).
|
62
|
+
should have_been_made
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'makes correct request when passed user' do
|
66
|
+
subject.api :get, 'user'
|
67
|
+
a_get('user.json').
|
68
|
+
with(:query => {:access_token => 'some_token'}).
|
69
|
+
should have_been_made
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns correct parsed object' do
|
73
|
+
res = subject.api :get, 'user'
|
74
|
+
target = begin
|
75
|
+
MultiJson.load fixture('user.json')
|
76
|
+
end
|
77
|
+
res.should eq(target)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns nil from non existent endpoint' do
|
81
|
+
res = subject.api :get, 'non_existent'
|
82
|
+
res.should eq(nil)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'returns nil from mangled data' do
|
86
|
+
res = subject.api :get, 'mangled'
|
87
|
+
res.should eq(nil)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
describe 'api :post' do
|
93
|
+
|
94
|
+
before do
|
95
|
+
stub_post('updates/create.json').
|
96
|
+
with(
|
97
|
+
:query => {:access_token => 'some_token'},
|
98
|
+
:body => {
|
99
|
+
"media"=>{"link"=>"http://google.com"},
|
100
|
+
"profile_ids"=>[
|
101
|
+
"4eb854340acb04e870000010",
|
102
|
+
"4eb9276e0acb04bb81000067"],
|
103
|
+
"text"=>"This is an example update"}).
|
104
|
+
to_return(
|
105
|
+
:body => fixture('success.json'),
|
106
|
+
:status => 200)
|
107
|
+
|
108
|
+
stub_post('updates/creatify.json').
|
109
|
+
with(
|
110
|
+
:query => {:access_token => 'some_token'},
|
111
|
+
:body => {
|
112
|
+
"media"=>{"link"=>"http://google.com"},
|
113
|
+
"profile_ids"=>[
|
114
|
+
"4eb854340acb04e870000010",
|
115
|
+
"4eb9276e0acb04bb81000067"],
|
116
|
+
"text"=>"This is an example update"}).
|
117
|
+
to_return(
|
118
|
+
:status => 200)
|
119
|
+
|
120
|
+
stub_request(
|
121
|
+
:post,
|
122
|
+
"https://api.bufferapp.com/1/updates/create.json?access_token=some_token").
|
123
|
+
with(:body => {"profile_ids"=>["fdf", "1"], "text"=>["a237623", "asb"]},
|
124
|
+
:headers => {
|
125
|
+
'Accept'=>'*/*',
|
126
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
127
|
+
'User-Agent'=>'Ruby'}).
|
128
|
+
to_return(:status => 200, :body => "", :headers => {})
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should make the correct POST to updates/create.json' do
|
132
|
+
subject.api :post,
|
133
|
+
'updates/create.json',
|
134
|
+
:text => "This is an example update",
|
135
|
+
:profile_ids => [
|
136
|
+
'4eb854340acb04e870000010',
|
137
|
+
'4eb9276e0acb04bb81000067'],
|
138
|
+
:media => {:link => "http://google.com"}
|
139
|
+
a_post('updates/create.json').
|
140
|
+
with(
|
141
|
+
:query => {:access_token => 'some_token'},
|
142
|
+
:body => fixture_contents('create_body.txt')).
|
143
|
+
should have_been_made
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should return a correctly parsed object' do
|
147
|
+
res = subject.api :post,
|
148
|
+
'updates/create.json',
|
149
|
+
:text => "This is an example update",
|
150
|
+
:profile_ids => [
|
151
|
+
'4eb854340acb04e870000010',
|
152
|
+
'4eb9276e0acb04bb81000067'],
|
153
|
+
:media => {:link => "http://google.com"}
|
154
|
+
res['success'].should be_true
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should return nil from non existent endpoint' do
|
158
|
+
res = subject.api :post,
|
159
|
+
'updates/creatify.json',
|
160
|
+
:text => "This is an example update",
|
161
|
+
:profile_ids => [
|
162
|
+
'4eb854340acb04e870000010',
|
163
|
+
'4eb9276e0acb04bb81000067'],
|
164
|
+
:media => {:link => "http://google.com"}
|
165
|
+
res.should eq(nil)
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should return nil when passes crap' do
|
169
|
+
res = subject.api :post,
|
170
|
+
'updates/create.json',
|
171
|
+
:text => [:a237623, 'asb'],
|
172
|
+
:profile_ids => ['fdf', '1']
|
173
|
+
res.should eq(nil)
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
describe 'get' do
|
181
|
+
|
182
|
+
subject do
|
183
|
+
Buffer::Client.new 'some_token'
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'is a method' do
|
187
|
+
subject.respond_to?(:get).should be_true
|
188
|
+
end
|
189
|
+
|
190
|
+
before do
|
191
|
+
stub_get('user.json').
|
192
|
+
with(:query => {:access_token => 'some_token'}).
|
193
|
+
to_return(
|
194
|
+
:body => fixture('user.json'),
|
195
|
+
:headers => {:content_type => 'application/json; charset=utf-8'})
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'makes correct request to user.json with access token' do
|
199
|
+
subject.get 'user.json'
|
200
|
+
a_get('user.json').
|
201
|
+
with(:query => {:access_token => 'some_token'}).
|
202
|
+
should have_been_made
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'makes correct request when passed user' do
|
206
|
+
subject.get 'user'
|
207
|
+
a_get('user.json').
|
208
|
+
with(:query => {:access_token => 'some_token'}).
|
209
|
+
should have_been_made
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
describe 'post' do
|
215
|
+
|
216
|
+
subject do
|
217
|
+
Buffer::Client.new 'some_token'
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'is a method' do
|
221
|
+
subject.respond_to?(:post).should be_true
|
222
|
+
end
|
223
|
+
|
224
|
+
before do
|
225
|
+
stub_post('updates/create.json').
|
226
|
+
with(
|
227
|
+
:query => {:access_token => 'some_token'},
|
228
|
+
:body => {
|
229
|
+
"media"=>{"link"=>"http://google.com"},
|
230
|
+
"profile_ids"=>[
|
231
|
+
"4eb854340acb04e870000010",
|
232
|
+
"4eb9276e0acb04bb81000067"],
|
233
|
+
"text"=>"This is an example update"}).
|
234
|
+
to_return(
|
235
|
+
:body => fixture('success.json'),
|
236
|
+
:status => 200)
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'should make the correct POST to updates/create.json' do
|
240
|
+
subject.post 'updates/create.json',
|
241
|
+
:text => "This is an example update",
|
242
|
+
:profile_ids => ['4eb854340acb04e870000010', '4eb9276e0acb04bb81000067'],
|
243
|
+
:media => {:link => "http://google.com"}
|
244
|
+
a_post('updates/create.json').
|
245
|
+
with(
|
246
|
+
:query => {:access_token => 'some_token'},
|
247
|
+
:body => fixture_contents('create_body.txt')).
|
248
|
+
should have_been_made
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
describe Buffer::User do
|
256
|
+
|
257
|
+
describe 'new' do
|
258
|
+
|
259
|
+
it 'accepts a token' do
|
260
|
+
user = Buffer::User.new 'some_token'
|
261
|
+
user.token.should eq('some_token')
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'rejects an integer token' do
|
265
|
+
lambda { user = Buffer::User.new 123 }.should raise_error
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'rejects an array token' do
|
269
|
+
lambda { user = Buffer::User.new [123, 'hello'] }.should raise_error
|
270
|
+
end
|
271
|
+
|
272
|
+
it 'rejects an hash token' do
|
273
|
+
lambda { user = Buffer::User.new :test => 123 }.should raise_error
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|
277
|
+
|
278
|
+
describe 'helpers' do
|
279
|
+
|
280
|
+
subject do
|
281
|
+
Buffer::User.new 'some_token'
|
282
|
+
end
|
283
|
+
|
284
|
+
before do
|
285
|
+
stub_get('user.json').
|
286
|
+
with(:query => {:access_token => 'some_token'}).
|
287
|
+
to_return(
|
288
|
+
:body => fixture('user.json'),
|
289
|
+
:headers => {:content_type => 'application/json; charset=utf-8'})
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'respond with correct id' do
|
293
|
+
subject.id.should eq('1234')
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'do not respond to eye_color' do
|
297
|
+
lambda { color = subject.eye_color }.should raise_error
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'respond to get' do
|
301
|
+
lambda { user = subject.get 'user' }.should_not raise_error
|
302
|
+
end
|
303
|
+
|
304
|
+
end
|
305
|
+
|
306
|
+
describe 'cache' do
|
307
|
+
|
308
|
+
subject do
|
309
|
+
Buffer::User.new 'some_token'
|
310
|
+
end
|
311
|
+
|
312
|
+
before do
|
313
|
+
stub_get('user.json').
|
314
|
+
with(:query => {:access_token => 'some_token'}).
|
315
|
+
to_return(
|
316
|
+
:body => fixture('user.json'),
|
317
|
+
:headers => {:content_type => 'application/json; charset=utf-8'})
|
318
|
+
end
|
319
|
+
|
320
|
+
describe 'access' do
|
321
|
+
|
322
|
+
before do
|
323
|
+
subject.id
|
324
|
+
end
|
325
|
+
|
326
|
+
it 'is used after accessing id once' do
|
327
|
+
id = subject.id
|
328
|
+
a_get('user.json').
|
329
|
+
should_not have_been_made
|
330
|
+
end
|
331
|
+
|
332
|
+
end
|
333
|
+
|
334
|
+
describe 'invalidation' do
|
335
|
+
|
336
|
+
before do
|
337
|
+
subject.id
|
338
|
+
end
|
339
|
+
|
340
|
+
it 'forces server access' do
|
341
|
+
subject.invalidate
|
342
|
+
id = subject.id
|
343
|
+
a_get('user.json').
|
344
|
+
with(:query => {:access_token => 'some_token'}).
|
345
|
+
should have_been_made.times(2)
|
346
|
+
end
|
347
|
+
|
348
|
+
end
|
349
|
+
|
350
|
+
end
|
351
|
+
|
352
|
+
end
|
353
|
+
|
354
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
text=This+is+an+example+update&profile_ids[]=4eb854340acb04e870000010&profile_ids[]=4eb9276e0acb04bb81000067&media[link]=http%3A%2F%2Fgoogle.com
|
@@ -0,0 +1 @@
|
|
1
|
+
{"success":true}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"_id":"1234","activity_at":5678,"created_at":1234,"id":"1234","plan":"free","referral_link":"http:\/\/bufferapp.com\/r\/abc","referral_token":"abc","secret_email":"buffer-abc@to.bufferapp.com","timezone":""}
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter 'spec'
|
4
|
+
end
|
5
|
+
require 'rspec'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
require 'multi_json'
|
8
|
+
require 'buffer'
|
9
|
+
|
10
|
+
# Taken from https://github.com/sferik/twitter/blob/master/spec/helper.rb
|
11
|
+
# for stubbing & mocking HTTP requests
|
12
|
+
|
13
|
+
def endpoint
|
14
|
+
'https://api.bufferapp.com/1/'
|
15
|
+
end
|
16
|
+
|
17
|
+
def a_get(path)
|
18
|
+
a_request(:get, endpoint + path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def a_post(path)
|
22
|
+
a_request(:post, endpoint + path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def stub_get(path)
|
26
|
+
stub_request(:get, endpoint + path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def stub_post(path)
|
30
|
+
stub_request(:post, endpoint + path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def fixture_path
|
34
|
+
File.expand_path("../fixtures", __FILE__)
|
35
|
+
end
|
36
|
+
|
37
|
+
def fixture(file)
|
38
|
+
File.new(fixture_path + '/' + file)
|
39
|
+
end
|
40
|
+
|
41
|
+
def fixture_contents(file)
|
42
|
+
File.open(fixture_path + '/' + file) { |f| f.read }
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: buffer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tom Ashworth
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: multi_json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: i18n
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: active_support
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '2.7'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.7'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: simplecov
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: webmock
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: Buffer API wrapper for Ruby
|
127
|
+
email:
|
128
|
+
- tom@phuu.net
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .gitignore
|
134
|
+
- Gemfile
|
135
|
+
- LICENSE
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- buffer.gemspec
|
139
|
+
- lib/buffer.rb
|
140
|
+
- lib/buffer/version.rb
|
141
|
+
- spec/buffer_spec.rb
|
142
|
+
- spec/fixtures/create_body.txt
|
143
|
+
- spec/fixtures/success.json
|
144
|
+
- spec/fixtures/user.json
|
145
|
+
- spec/helper.rb
|
146
|
+
homepage: ''
|
147
|
+
licenses: []
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
160
|
+
requirements:
|
161
|
+
- - ! '>='
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
requirements: []
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 1.8.24
|
167
|
+
signing_key:
|
168
|
+
specification_version: 3
|
169
|
+
summary: Buffer API wrapper for Ruby
|
170
|
+
test_files:
|
171
|
+
- spec/buffer_spec.rb
|
172
|
+
- spec/fixtures/create_body.txt
|
173
|
+
- spec/fixtures/success.json
|
174
|
+
- spec/fixtures/user.json
|
175
|
+
- spec/helper.rb
|