remind101 0.0.1 → 0.1.0
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/README.md +27 -11
- data/lib/remind101/client/groups.rb +41 -0
- data/lib/remind101/client/messages.rb +28 -0
- data/lib/remind101/client/subscribers.rb +36 -2
- data/lib/remind101/client.rb +2 -2
- data/lib/remind101/error.rb +13 -2
- data/lib/remind101/version.rb +1 -1
- data/spec/remind101/client_spec.rb +38 -21
- metadata +5 -5
- data/lib/remind101/client/classes.rb +0 -17
data/README.md
CHANGED
@@ -18,30 +18,30 @@ gem 'remind101'
|
|
18
18
|
remind101 = Remind101::Client.new(auth_token: 'token')
|
19
19
|
```
|
20
20
|
|
21
|
-
###
|
21
|
+
### groups
|
22
22
|
|
23
|
-
Returns an `Array` of `Hashie::Mash`'s for all the
|
23
|
+
Returns an `Array` of `Hashie::Mash`'s for all the groups for the currently
|
24
24
|
logged in user.
|
25
25
|
|
26
26
|
```ruby
|
27
|
-
remind101.
|
27
|
+
remind101.groups
|
28
28
|
# => [{ ... }]
|
29
29
|
```
|
30
30
|
|
31
|
-
### create\
|
31
|
+
### create\_group
|
32
32
|
|
33
|
-
Creates the
|
33
|
+
Creates the group and returns a `Hashie::Mash`.
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
remind101.
|
36
|
+
remind101.create_group class_name: 'Math 101'
|
37
37
|
```
|
38
38
|
|
39
|
-
### destroy\
|
39
|
+
### destroy\_group
|
40
40
|
|
41
|
-
Destroys the
|
41
|
+
Destroys the group with the given `id`.
|
42
42
|
|
43
43
|
```ruby
|
44
|
-
remind101.
|
44
|
+
remind101.destroy_group 1234
|
45
45
|
```
|
46
46
|
|
47
47
|
### messages
|
@@ -56,7 +56,7 @@ remind101.messages
|
|
56
56
|
|
57
57
|
### send\_message
|
58
58
|
|
59
|
-
Send a new message to all subscribers of the given
|
59
|
+
Send a new message to all subscribers of the given group. Returns a
|
60
60
|
`Hashie::Mash` for the created message.
|
61
61
|
|
62
62
|
```ruby
|
@@ -76,13 +76,29 @@ remind101.cancel_message 4321
|
|
76
76
|
### subscribers
|
77
77
|
|
78
78
|
Returns an `Array` of `Hashie::Mash`'s for all the subscribers of the given
|
79
|
-
|
79
|
+
group.
|
80
80
|
|
81
81
|
```ruby
|
82
82
|
remind101.subscribers 1234
|
83
83
|
# => [{ ... }]
|
84
84
|
```
|
85
85
|
|
86
|
+
### Validation Errors
|
87
|
+
|
88
|
+
When a validation error is returned (HTTP 422), a
|
89
|
+
`Remind101::Error::ValidationError` with be raised. The `#error` method on this
|
90
|
+
object will be a key/val hash of the errors.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
begin
|
94
|
+
remind101.create_group! class_name: '1'
|
95
|
+
rescue Remind101::Error::ValidationError => e
|
96
|
+
e.error.each do |attribute, errors|
|
97
|
+
p "#{attribute}: #{errors}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
86
102
|
## Contributing
|
87
103
|
|
88
104
|
1. Fork it
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Remind101::Client::Groups
|
2
|
+
extend Remind101::Client::Rescuable
|
3
|
+
|
4
|
+
# Public: Returns all groups for the current user.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# remind101.groups
|
9
|
+
# # => [{ ... }]
|
10
|
+
#
|
11
|
+
# Returns an Array of all groups.
|
12
|
+
def groups
|
13
|
+
api_get('/groups').body
|
14
|
+
end
|
15
|
+
|
16
|
+
# Public: Creates a new group.
|
17
|
+
#
|
18
|
+
# Examples
|
19
|
+
#
|
20
|
+
# remind101.create_group! name: 'Math 101'
|
21
|
+
# # => { :id => 4321, :name => "Math 101", ... }
|
22
|
+
#
|
23
|
+
# Returns the created group.
|
24
|
+
def create_group!(hash)
|
25
|
+
api_post('/groups', group: hash).body
|
26
|
+
end
|
27
|
+
def_rescued :create_group, :create_group!
|
28
|
+
|
29
|
+
# Public: Destroys an existing group.
|
30
|
+
#
|
31
|
+
# Examples
|
32
|
+
#
|
33
|
+
# remind101.destroy_group! 4321
|
34
|
+
# # => { :id => 4321, :name => "Math 101", ... }
|
35
|
+
#
|
36
|
+
# Returns the destroyed group.
|
37
|
+
def destroy_group!(group_id)
|
38
|
+
api_delete("/groups/#{group_id}").body
|
39
|
+
end
|
40
|
+
def_rescued :destroy_group, :destroy_group!
|
41
|
+
end
|
@@ -1,10 +1,28 @@
|
|
1
1
|
module Remind101::Client::Messages
|
2
2
|
extend Remind101::Client::Rescuable
|
3
3
|
|
4
|
+
# Public: Returns all messages for the current user.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# remind101.messages
|
9
|
+
# # => [{ ... }]
|
10
|
+
#
|
11
|
+
# Returns an Array of all messages.
|
4
12
|
def messages
|
5
13
|
api_get('/messages').body
|
6
14
|
end
|
7
15
|
|
16
|
+
# Public: Creates a new message.
|
17
|
+
#
|
18
|
+
# Also aliased as `#send_message!`.
|
19
|
+
#
|
20
|
+
# Examples
|
21
|
+
#
|
22
|
+
# remind101.create_message! body: 'Hello World!', group_ids: [1234]
|
23
|
+
# # => { :id => 4321, :body => "Hello World!", :group_ids => [1234], ... }
|
24
|
+
#
|
25
|
+
# Returns the created message.
|
8
26
|
def create_message!(hash)
|
9
27
|
api_post('/messages', message: hash).body
|
10
28
|
end
|
@@ -12,6 +30,16 @@ module Remind101::Client::Messages
|
|
12
30
|
alias_method :send_message!, :create_message!
|
13
31
|
alias_method :send_message, :create_message
|
14
32
|
|
33
|
+
# Public: Destroy an existing message.
|
34
|
+
#
|
35
|
+
# Also aliased as `cancel_message!`.
|
36
|
+
#
|
37
|
+
# Examples
|
38
|
+
#
|
39
|
+
# remind101.destroy_message! 4321
|
40
|
+
# # => { :id => 4321, :body => "Hello World!", :group_ids => [1234], ... }
|
41
|
+
#
|
42
|
+
# Returns the destroyed message.
|
15
43
|
def destroy_message!(message_id)
|
16
44
|
api_delete("/messages/#{message_id}").body
|
17
45
|
end
|
@@ -1,5 +1,39 @@
|
|
1
1
|
module Remind101::Client::Subscribers
|
2
|
-
|
3
|
-
|
2
|
+
extend Remind101::Client::Rescuable
|
3
|
+
|
4
|
+
# Public: Returns all subscribers for the given group.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# remind101.subscribers 1234
|
9
|
+
# #=> [{ ... }]
|
10
|
+
#
|
11
|
+
# Returns an Array of all subscribers.
|
12
|
+
def subscribers(group_id)
|
13
|
+
api_get("/groups/#{group_id}/subscribers").body
|
4
14
|
end
|
15
|
+
|
16
|
+
# Public: Removes a subscriber from the group.
|
17
|
+
#
|
18
|
+
# Examples
|
19
|
+
#
|
20
|
+
# remind101.remove_subscriber! 1234, 4321
|
21
|
+
#
|
22
|
+
# Returns the removed subscriber.
|
23
|
+
def remove_subscriber!(group_id, subscriber_id)
|
24
|
+
api_delete("/groups/#{group_id}/subscribers/#{subscriber_id}").body
|
25
|
+
end
|
26
|
+
def_rescued :remove_subscriber, :remove_subscriber!
|
27
|
+
|
28
|
+
# Public: Removes all subscribers from the group.
|
29
|
+
#
|
30
|
+
# Examples
|
31
|
+
#
|
32
|
+
# remind101.remove_subscribers!
|
33
|
+
#
|
34
|
+
# Returns true if all subscribers were removed.
|
35
|
+
def remove_subscribers!(group_id)
|
36
|
+
api_delete("/groups/#{group_id}/subscribers").body
|
37
|
+
end
|
38
|
+
def_rescued :remove_subscribers, :remove_subscribers!
|
5
39
|
end
|
data/lib/remind101/client.rb
CHANGED
@@ -2,12 +2,12 @@ module Remind101
|
|
2
2
|
class Client
|
3
3
|
require 'remind101/client/rescuable'
|
4
4
|
require 'remind101/client/connection'
|
5
|
-
require 'remind101/client/
|
5
|
+
require 'remind101/client/groups'
|
6
6
|
require 'remind101/client/messages'
|
7
7
|
require 'remind101/client/subscribers'
|
8
8
|
|
9
9
|
include Connection
|
10
|
-
include
|
10
|
+
include Groups
|
11
11
|
include Messages
|
12
12
|
include Subscribers
|
13
13
|
|
data/lib/remind101/error.rb
CHANGED
@@ -5,7 +5,18 @@ module Remind101
|
|
5
5
|
const_set(const, Faraday::Error.const_get(const))
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
module ErrorsBody
|
9
|
+
def error
|
10
|
+
response.body.error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class BadInput < ClientError
|
15
|
+
include ErrorsBody
|
16
|
+
end
|
17
|
+
|
18
|
+
class ValidationError < ClientError
|
19
|
+
include ErrorsBody
|
20
|
+
end
|
10
21
|
end
|
11
22
|
end
|
data/lib/remind101/version.rb
CHANGED
@@ -1,31 +1,32 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Remind101::Client do
|
4
|
-
let(:
|
5
|
-
let(:message_id) { 4321 }
|
6
|
-
let(:
|
4
|
+
let(:group_id ) { 1234 }
|
5
|
+
let(:message_id ) { 4321 }
|
6
|
+
let(:subscriber_id) { 789 }
|
7
|
+
let(:client ) { described_class.new }
|
7
8
|
|
8
|
-
describe '#
|
9
|
-
before { stub_request(:get, 'https://api.remind101.com/v2/
|
9
|
+
describe '#groups' do
|
10
|
+
before { stub_request(:get, 'https://api.remind101.com/v2/groups') }
|
10
11
|
|
11
|
-
it 'gets the
|
12
|
-
client.
|
12
|
+
it 'gets the groups' do
|
13
|
+
client.groups
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
|
-
describe '#
|
17
|
-
before { stub_request(:post, 'https://api.remind101.com/v2/
|
17
|
+
describe '#create_group!' do
|
18
|
+
before { stub_request(:post, 'https://api.remind101.com/v2/groups') }
|
18
19
|
|
19
|
-
it 'creates the
|
20
|
-
client.
|
20
|
+
it 'creates the group' do
|
21
|
+
client.create_group! name: 'Math 101'
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
describe '#
|
25
|
-
before { stub_request(:delete, "https://api.remind101.com/v2/
|
25
|
+
describe '#destroy_group!' do
|
26
|
+
before { stub_request(:delete, "https://api.remind101.com/v2/groups/#{group_id}") }
|
26
27
|
|
27
|
-
it 'destroys the
|
28
|
-
client.
|
28
|
+
it 'destroys the group' do
|
29
|
+
client.destroy_group! group_id
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
@@ -37,27 +38,43 @@ describe Remind101::Client do
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
describe '#create_message' do
|
41
|
+
describe '#create_message!' do
|
41
42
|
before { stub_request(:post, 'https://api.remind101.com/v2/messages') }
|
42
43
|
|
43
44
|
it 'creates the message' do
|
44
|
-
client.create_message body: "There's a test tomorrow!", group_ids: [
|
45
|
+
client.create_message! body: "There's a test tomorrow!", group_ids: [group_id]
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
describe '#destroy_message' do
|
49
|
+
describe '#destroy_message!' do
|
49
50
|
before { stub_request(:delete, "https://api.remind101.com/v2/messages/#{message_id}") }
|
50
51
|
|
51
52
|
it 'destroys the message' do
|
52
|
-
client.destroy_message message_id
|
53
|
+
client.destroy_message! message_id
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
57
|
describe '#subscribers' do
|
57
|
-
before { stub_request(:get, "https://api.remind101.com/v2/
|
58
|
+
before { stub_request(:get, "https://api.remind101.com/v2/groups/#{group_id}/subscribers") }
|
58
59
|
|
59
60
|
it 'gets the subscribers' do
|
60
|
-
client.subscribers(
|
61
|
+
client.subscribers(group_id)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#remove_subscriber!' do
|
66
|
+
before { stub_request(:delete, "https://api.remind101.com/v2/groups/#{group_id}/subscribers/#{subscriber_id}") }
|
67
|
+
|
68
|
+
it 'removes the subscriber' do
|
69
|
+
client.remove_subscriber!(group_id, subscriber_id)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#remove_subscribers!' do
|
74
|
+
before { stub_request(:delete, "https://api.remind101.com/v2/groups/#{group_id}/subscribers") }
|
75
|
+
|
76
|
+
it 'removes the subscriber' do
|
77
|
+
client.remove_subscribers!(group_id)
|
61
78
|
end
|
62
79
|
end
|
63
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remind101
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -162,8 +162,8 @@ files:
|
|
162
162
|
- Rakefile
|
163
163
|
- lib/remind101.rb
|
164
164
|
- lib/remind101/client.rb
|
165
|
-
- lib/remind101/client/classes.rb
|
166
165
|
- lib/remind101/client/connection.rb
|
166
|
+
- lib/remind101/client/groups.rb
|
167
167
|
- lib/remind101/client/messages.rb
|
168
168
|
- lib/remind101/client/rescuable.rb
|
169
169
|
- lib/remind101/client/subscribers.rb
|
@@ -190,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
190
|
version: '0'
|
191
191
|
segments:
|
192
192
|
- 0
|
193
|
-
hash: -
|
193
|
+
hash: -1908290670246690912
|
194
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
195
|
none: false
|
196
196
|
requirements:
|
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
199
|
version: '0'
|
200
200
|
segments:
|
201
201
|
- 0
|
202
|
-
hash: -
|
202
|
+
hash: -1908290670246690912
|
203
203
|
requirements: []
|
204
204
|
rubyforge_project:
|
205
205
|
rubygems_version: 1.8.23
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Remind101::Client::Classes
|
2
|
-
extend Remind101::Client::Rescuable
|
3
|
-
|
4
|
-
def classes
|
5
|
-
api_get('/classes').body
|
6
|
-
end
|
7
|
-
|
8
|
-
def create_class!(hash)
|
9
|
-
api_post('/classes', group: hash).body
|
10
|
-
end
|
11
|
-
def_rescued :create_class, :create_class!
|
12
|
-
|
13
|
-
def destroy_class!(class_id)
|
14
|
-
api_delete("/classes/#{class_id}").body
|
15
|
-
end
|
16
|
-
def_rescued :destroy_class, :destroy_class!
|
17
|
-
end
|