groupme-api 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -0
- data/Gemfile.lock +1 -1
- data/groupme-api.gemspec +1 -0
- data/lib/groupme.rb +6 -0
- data/lib/groupme/client.rb +14 -4
- data/lib/groupme/configuration.rb +31 -0
- data/lib/groupme/errors.rb +5 -0
- data/lib/groupme/group.rb +9 -0
- data/lib/groupme/version.rb +1 -1
- data/spec/groupme/client_spec.rb +49 -18
- data/spec/groupme/configuration_spec.rb +59 -0
- data/spec/groupme/group_spec.rb +15 -0
- data/spec/support/groupme.rb +16 -2
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ac0f859ba8eaddcf6b9acf212bfef6e20915aab5
|
4
|
+
data.tar.gz: d5c1743b72c49eede05915faf033c9206e7c7e91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ea0417528eab7af4f850faca868e6fd2d734749b335e326aeca49fdacfe9d8b2a15217c9e71aeb8748654b94b256fc60f660359a2c27f6f9d8902b32360baac
|
7
|
+
data.tar.gz: fbb9f36f96b639106b7a2e818f4be8916941c240555a1b51b2615b5036a08cf7884d11007db686f2206886a8146c0ebcd62404d63946791d6f3be4109b63a2e6
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
data/Gemfile.lock
CHANGED
data/groupme-api.gemspec
CHANGED
data/lib/groupme.rb
CHANGED
@@ -4,7 +4,13 @@ require 'httpclient'
|
|
4
4
|
require 'json'
|
5
5
|
|
6
6
|
require 'groupme/client'
|
7
|
+
require 'groupme/configuration'
|
8
|
+
require 'groupme/errors'
|
9
|
+
require 'groupme/group'
|
7
10
|
require 'groupme/version'
|
8
11
|
|
9
12
|
module GroupMe
|
13
|
+
def self.reset!
|
14
|
+
@configuration = Configuration.new
|
15
|
+
end
|
10
16
|
end
|
data/lib/groupme/client.rb
CHANGED
@@ -5,13 +5,15 @@ module GroupMe
|
|
5
5
|
API_BASE_URL = 'https://api.groupme.com/v3/'
|
6
6
|
API_DEFAULT_HEADER = { 'Content-Type': 'application/json' }.freeze
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
attr_accessor :access_token
|
9
|
+
|
10
|
+
def initialize(args = {})
|
11
|
+
@access_token = args[:access_token] || GroupMe.configuration.access_token
|
10
12
|
@client = HTTPClient.new(base_url: API_BASE_URL, default_header: API_DEFAULT_HEADER)
|
11
13
|
end
|
12
14
|
|
13
|
-
def request(method, path, query: {}, body:
|
14
|
-
response = @client.request(method, path, { token: @access_token }.merge(query), body
|
15
|
+
def request(method, path, query: {}, body: nil)
|
16
|
+
response = @client.request(method, path, { token: @access_token }.merge(query), body&.to_json)
|
15
17
|
[parse_response_body(response), response.status]
|
16
18
|
end
|
17
19
|
|
@@ -35,4 +37,12 @@ module GroupMe
|
|
35
37
|
JSON.parse(response.body, symbolize_names: true).fetch(:response)
|
36
38
|
end
|
37
39
|
end
|
40
|
+
|
41
|
+
def self.client
|
42
|
+
@client ||= Client.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.client=(client)
|
46
|
+
@client = client
|
47
|
+
end
|
38
48
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GroupMe
|
4
|
+
class Configuration
|
5
|
+
API_MAX_GROUPS_PER_PAGE = 500
|
6
|
+
|
7
|
+
attr_writer :access_token, :groups_per_page
|
8
|
+
|
9
|
+
def access_token
|
10
|
+
raise MissingConfigurationError unless @access_token
|
11
|
+
|
12
|
+
@access_token
|
13
|
+
end
|
14
|
+
|
15
|
+
def groups_per_page
|
16
|
+
@groups_per_page || API_MAX_GROUPS_PER_PAGE
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configuration
|
21
|
+
@configuration ||= Configuration.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configuration=(configuration)
|
25
|
+
@configuration = configuration
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure
|
29
|
+
yield(configuration)
|
30
|
+
end
|
31
|
+
end
|
data/lib/groupme/version.rb
CHANGED
data/spec/groupme/client_spec.rb
CHANGED
@@ -1,26 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
RSpec.describe GroupMe::Client do
|
4
|
-
|
5
|
-
|
4
|
+
include_context :with_default_groupme_configuration
|
5
|
+
|
6
|
+
let(:client) { GroupMe::Client.new(access_token: access_token) }
|
7
|
+
let(:base_url) { GroupMe::Client::API_BASE_URL }
|
6
8
|
|
7
9
|
describe '.new' do
|
8
|
-
context 'when :access_token
|
9
|
-
|
10
|
-
|
10
|
+
context 'when :access_token is not supplied' do
|
11
|
+
let(:client) { GroupMe::Client.new }
|
12
|
+
|
13
|
+
it 'should use configured :access_token' do
|
14
|
+
expect(client.access_token).to eq(GroupMe.configuration.access_token)
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
14
|
-
context 'when :access_token is
|
15
|
-
|
16
|
-
|
18
|
+
context 'when :access_token is supplied' do
|
19
|
+
let(:client) { GroupMe::Client.new(access_token: new_access_token) }
|
20
|
+
|
21
|
+
it 'should not use configured :access_token' do
|
22
|
+
expect(client.access_token).not_to eq(GroupMe.configuration.access_token)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should use the supplied :access_token' do
|
26
|
+
expect(client.access_token).to eq(new_access_token)
|
17
27
|
end
|
18
28
|
end
|
19
29
|
end
|
20
30
|
|
21
31
|
describe '#request' do
|
22
|
-
let(:stubbed_data)
|
23
|
-
let(:stubbed_response_body)
|
32
|
+
let(:stubbed_data) { { id: 1, name: 'Group' } }
|
33
|
+
let(:stubbed_response_body) { { response: stubbed_data }.to_json }
|
24
34
|
let(:stubbed_response_status) { 200 }
|
25
35
|
|
26
36
|
before do
|
@@ -30,31 +40,31 @@ RSpec.describe GroupMe::Client do
|
|
30
40
|
)
|
31
41
|
end
|
32
42
|
|
33
|
-
context 'when
|
43
|
+
context 'when no parameters are supplied' do
|
34
44
|
it 'should send the correct HTTP request' do
|
35
45
|
client.request(:get, 'groups')
|
36
46
|
|
37
|
-
expect(WebMock).to have_requested(:get, "#{base_url}groups").with(query: { token:
|
47
|
+
expect(WebMock).to have_requested(:get, "#{base_url}groups").with(query: { token: access_token })
|
38
48
|
end
|
39
49
|
end
|
40
50
|
|
41
|
-
context 'when
|
51
|
+
context 'when query parameters are supplied' do
|
42
52
|
it 'should send the correct HTTP request' do
|
43
53
|
client.request(:get, 'groups', query: { per_page: 1 })
|
44
54
|
|
45
|
-
expect(WebMock).to have_requested(:get, "#{base_url}groups").with(query: { token:
|
55
|
+
expect(WebMock).to have_requested(:get, "#{base_url}groups").with(query: { token: access_token, per_page: 1 })
|
46
56
|
end
|
47
57
|
end
|
48
58
|
|
49
|
-
context 'when
|
59
|
+
context 'when body parameters are supplied' do
|
50
60
|
it 'should send the correct HTTP request' do
|
51
61
|
client.request(:post, 'groups', body: { name: 'Group' })
|
52
62
|
|
53
|
-
expect(WebMock).to have_requested(:post, "#{base_url}groups?token=#{
|
63
|
+
expect(WebMock).to have_requested(:post, "#{base_url}groups?token=#{access_token}").with(body: { name: 'Group' }.to_json)
|
54
64
|
end
|
55
65
|
end
|
56
66
|
|
57
|
-
context 'when response is successful' do
|
67
|
+
context 'when the response is successful' do
|
58
68
|
let(:stubbed_response_body) { { response: stubbed_data }.to_json }
|
59
69
|
let(:stubbed_response_status) { 201 }
|
60
70
|
|
@@ -71,7 +81,7 @@ RSpec.describe GroupMe::Client do
|
|
71
81
|
end
|
72
82
|
end
|
73
83
|
|
74
|
-
context 'when response is unsuccessful' do
|
84
|
+
context 'when the response is unsuccessful' do
|
75
85
|
let(:stubbed_response_body) { '' }
|
76
86
|
let(:stubbed_response_status) { [404, 'Not Found'] }
|
77
87
|
|
@@ -161,3 +171,24 @@ RSpec.describe GroupMe::Client do
|
|
161
171
|
end
|
162
172
|
end
|
163
173
|
end
|
174
|
+
|
175
|
+
RSpec.describe GroupMe do
|
176
|
+
include_context :with_default_groupme_configuration
|
177
|
+
|
178
|
+
describe '.client' do
|
179
|
+
it 'should return a GroupMe::Client object' do
|
180
|
+
expect(GroupMe.client).to be_a_instance_of(GroupMe::Client)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe '.client=' do
|
185
|
+
it 'should set a new default client' do
|
186
|
+
old_client = GroupMe.client
|
187
|
+
new_client = GroupMe::Client.new
|
188
|
+
GroupMe.client = new_client
|
189
|
+
|
190
|
+
expect(GroupMe.client).not_to eq(old_client)
|
191
|
+
expect(GroupMe.client).to eq(new_client)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe GroupMe::Configuration do
|
6
|
+
before(:each) { GroupMe.reset! }
|
7
|
+
|
8
|
+
describe '#access_token' do
|
9
|
+
context 'when :access_token is not configured' do
|
10
|
+
it 'should raise an error' do
|
11
|
+
expect { GroupMe.configuration.access_token }.to raise_error(GroupMe::MissingConfigurationError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when :access_token is configured' do
|
16
|
+
include_context :with_default_groupme_configuration
|
17
|
+
|
18
|
+
it 'should return the access_token' do
|
19
|
+
expect(GroupMe.configuration.access_token).to eq(access_token)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
RSpec.describe GroupMe do
|
26
|
+
describe '.configuration' do
|
27
|
+
it 'should return a GroupMe::Configuration object' do
|
28
|
+
expect(GroupMe.configuration).to be_an_instance_of(GroupMe::Configuration)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.configuration=' do
|
33
|
+
it 'should set a new default configuration' do
|
34
|
+
old_configuration = GroupMe.configuration
|
35
|
+
new_configuration = GroupMe::Configuration.new
|
36
|
+
GroupMe.configuration = new_configuration
|
37
|
+
|
38
|
+
expect(GroupMe.configuration).not_to eq(old_configuration)
|
39
|
+
expect(GroupMe.configuration).to eq(new_configuration)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'configure' do
|
44
|
+
it 'should set configuration attributes' do
|
45
|
+
GroupMe.configure { |config| config.access_token = access_token }
|
46
|
+
|
47
|
+
expect(GroupMe.configuration.access_token).to eq(access_token)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'reset!' do
|
52
|
+
it 'should reset the configuration' do
|
53
|
+
old_configuration = GroupMe.configuration
|
54
|
+
GroupMe.reset!
|
55
|
+
|
56
|
+
expect(GroupMe.configuration).not_to eq(old_configuration)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe GroupMe::Group do
|
4
|
+
include_context :with_default_groupme_configuration
|
5
|
+
|
6
|
+
let(:base_url) { GroupMe::Client::API_BASE_URL }
|
7
|
+
|
8
|
+
describe '#all' do
|
9
|
+
it 'should send the correct HTTP request' do
|
10
|
+
_groups = GroupMe::Group.all
|
11
|
+
|
12
|
+
expect(WebMock).to have_requested(:get, "#{base_url}groups").with(query: { token: access_token, omit: :memberships, per_page: GroupMe.configuration.groups_per_page })
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/support/groupme.rb
CHANGED
@@ -2,5 +2,19 @@
|
|
2
2
|
|
3
3
|
require 'securerandom'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
RSpec.shared_context :with_defined_access_token do
|
6
|
+
let(:access_token) { 'cQOvtsbxn7mHCS6yRimKuKHwXCGtqRwcU4E4NToe' }
|
7
|
+
let(:new_access_token) { SecureRandom.base64(30).tr('+', '0') }
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec.shared_context :with_default_groupme_configuration do
|
11
|
+
before(:each) do
|
12
|
+
GroupMe.configure do |config|
|
13
|
+
config.access_token = 'cQOvtsbxn7mHCS6yRimKuKHwXCGtqRwcU4E4NToe'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.include_context :with_defined_access_token
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groupme-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kinnell Shah
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- ".gitignore"
|
146
146
|
- ".rspec"
|
147
147
|
- ".rubocop.yml"
|
148
|
+
- ".ruby-version"
|
148
149
|
- ".travis.yml"
|
149
150
|
- Gemfile
|
150
151
|
- Gemfile.lock
|
@@ -156,9 +157,14 @@ files:
|
|
156
157
|
- lib/groupme-api.rb
|
157
158
|
- lib/groupme.rb
|
158
159
|
- lib/groupme/client.rb
|
160
|
+
- lib/groupme/configuration.rb
|
161
|
+
- lib/groupme/errors.rb
|
162
|
+
- lib/groupme/group.rb
|
159
163
|
- lib/groupme/version.rb
|
160
164
|
- lib/groupme_api.rb
|
161
165
|
- spec/groupme/client_spec.rb
|
166
|
+
- spec/groupme/configuration_spec.rb
|
167
|
+
- spec/groupme/group_spec.rb
|
162
168
|
- spec/groupme_spec.rb
|
163
169
|
- spec/spec_helper.rb
|
164
170
|
- spec/support/groupme.rb
|
@@ -175,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
175
181
|
requirements:
|
176
182
|
- - ">="
|
177
183
|
- !ruby/object:Gem::Version
|
178
|
-
version:
|
184
|
+
version: 2.3.0
|
179
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
186
|
requirements:
|
181
187
|
- - ">="
|
@@ -183,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
189
|
version: '0'
|
184
190
|
requirements: []
|
185
191
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.
|
192
|
+
rubygems_version: 2.5.1
|
187
193
|
signing_key:
|
188
194
|
specification_version: 4
|
189
195
|
summary: A Ruby wrapper for GroupMe REST API (v3)
|