groupme-api 0.4.1 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bbeb3119bd9c4da20719fc209bc4a56ccdc02a5579983c285d8cf0fa083491b
4
- data.tar.gz: fd177ceab8223f93a15a9d9b1dd87fec8817946556fcb726ad260329d4ec8e41
3
+ metadata.gz: 570e2a4a593dbf2b1230e6613444e778caa494e9a0c04675632e9b0eafab7ed9
4
+ data.tar.gz: 2432e495fa8a324c8b6da9edd65d2a8cf2ed7ee315a0561e563fd11981a129be
5
5
  SHA512:
6
- metadata.gz: 994989c42e6e1cdca00f40e5e1bd16184b8a13374e8486a7b60059db2398422c62b8f7413c996d434a17cc4850deda4f89d2ae37554832f84cd6026f8f00bf14
7
- data.tar.gz: 2a91c345f5a0452c79737c6fca76ed13936ba91a51994f6303578c289011f24edb2524e14b21c3b8aafac14ea8c7318ff0035d5297b4dbacd0ec4ccfcd4ba550
6
+ metadata.gz: 3fe24ea9b1550413b7f3da932e134bfc45056c436a3068ae1158adf04a3b9b5f0048c9ea5ded585d541c406ea768595fee2375fc10d2d849bd17ef4ea565f108
7
+ data.tar.gz: 5c7f672ccafb76b8d36ba8f0d880272b35786d5f770e9be9a1897487394e9a0f0a4d9f39274fda11957b6199bbeb3d8e3d542429d065740eb0c24f18194c714f
@@ -1,22 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- groupme-api (0.4.1)
4
+ groupme-api (0.5.0)
5
5
  httpclient (~> 2.8)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (5.2.1)
11
- concurrent-ruby (~> 1.0, >= 1.0.2)
12
- i18n (>= 0.7, < 2)
13
- minitest (~> 5.1)
14
- tzinfo (~> 1.1)
15
10
  addressable (2.5.2)
16
11
  public_suffix (>= 2.0.2, < 4.0)
17
- backports (3.11.4)
18
12
  coderay (1.1.2)
19
- concurrent-ruby (1.0.5)
20
13
  coveralls (0.8.22)
21
14
  json (>= 1.8, < 3)
22
15
  simplecov (~> 0.16.1)
@@ -45,18 +38,13 @@ GEM
45
38
  rspec (>= 2.99.0, < 4.0)
46
39
  hashdiff (0.3.7)
47
40
  httpclient (2.8.3)
48
- i18n (1.1.0)
49
- concurrent-ruby (~> 1.0)
50
41
  json (2.1.0)
51
42
  listen (3.1.5)
52
43
  rb-fsevent (~> 0.9, >= 0.9.4)
53
44
  rb-inotify (~> 0.9, >= 0.9.7)
54
45
  ruby_dep (~> 1.2)
55
46
  lumberjack (1.0.13)
56
- method_source (0.9.0)
57
- minitest (5.11.3)
58
- multi_json (1.13.1)
59
- mustermann (1.0.3)
47
+ method_source (0.9.1)
60
48
  nenv (0.3.0)
61
49
  notiffany (0.1.1)
62
50
  nenv (~> 0.1)
@@ -65,9 +53,6 @@ GEM
65
53
  coderay (~> 1.1.0)
66
54
  method_source (~> 0.9.0)
67
55
  public_suffix (3.0.3)
68
- rack (2.0.5)
69
- rack-protection (2.0.3)
70
- rack
71
56
  rake (10.5.0)
72
57
  rb-fsevent (0.10.3)
73
58
  rb-inotify (0.9.10)
@@ -78,7 +63,7 @@ GEM
78
63
  rspec-mocks (~> 3.8.0)
79
64
  rspec-core (3.8.0)
80
65
  rspec-support (~> 3.8.0)
81
- rspec-expectations (3.8.1)
66
+ rspec-expectations (3.8.2)
82
67
  diff-lcs (>= 1.2.0, < 2.0)
83
68
  rspec-support (~> 3.8.0)
84
69
  rspec-mocks (3.8.0)
@@ -93,27 +78,11 @@ GEM
93
78
  json (>= 1.8, < 3)
94
79
  simplecov-html (~> 0.10.0)
95
80
  simplecov-html (0.10.2)
96
- sinatra (2.0.3)
97
- mustermann (~> 1.0)
98
- rack (~> 2.0)
99
- rack-protection (= 2.0.3)
100
- tilt (~> 2.0)
101
- sinatra-contrib (2.0.3)
102
- activesupport (>= 4.0.0)
103
- backports (>= 2.8.2)
104
- multi_json
105
- mustermann (~> 1.0)
106
- rack-protection (= 2.0.3)
107
- sinatra (= 2.0.3)
108
- tilt (>= 1.3, < 3)
109
- term-ansicolor (1.6.0)
81
+ term-ansicolor (1.7.0)
110
82
  tins (~> 1.0)
111
83
  thor (0.19.4)
112
- thread_safe (0.3.6)
113
- tilt (2.0.8)
114
- tins (1.16.3)
115
- tzinfo (1.2.5)
116
- thread_safe (~> 0.1)
84
+ tins (1.18.0)
85
+ vcr (4.0.0)
117
86
  webmock (3.4.2)
118
87
  addressable (>= 2.3.6)
119
88
  crack (>= 0.3.2)
@@ -130,8 +99,7 @@ DEPENDENCIES
130
99
  rake (~> 10.0)
131
100
  rspec (~> 3.8)
132
101
  simplecov (~> 0.15)
133
- sinatra (~> 2.0)
134
- sinatra-contrib (~> 2.0)
102
+ vcr (~> 4.0)
135
103
  webmock (~> 3.4)
136
104
 
137
105
  BUNDLED WITH
data/Guardfile CHANGED
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- guard :rspec, cmd: 'rspec' do
3
+ guard :rspec, cmd: 'bundle exec rspec' do
4
4
  watch(%r{^spec/.+_spec\.rb$})
5
5
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
6
  watch('spec/spec_helper.rb') { 'spec' }
7
- watch(%r{^spec/fixtures/(.+)\.json$}) { 'spec' }
8
7
  watch(%r{^spec/support/(.+)$}) { 'spec' }
9
8
  end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Kinnell Shah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # GroupMe Ruby Gem (WIP)
1
+ # GroupMe Ruby Gem (BETA)
2
2
  [![Build Status](https://travis-ci.org/kinnell/groupme-ruby-gem.svg?branch=master)](https://travis-ci.org/kinnell/groupme-ruby-gem)
3
3
  [![Coverage Status](https://coveralls.io/repos/github/kinnell/groupme-ruby-gem/badge.svg?branch=master)](https://coveralls.io/github/kinnell/groupme-ruby-gem?branch=master)
4
4
 
@@ -25,9 +25,11 @@ Or install it yourself as:
25
25
  Get a developer access token at: https://dev.groupme.com/
26
26
 
27
27
  ```ruby
28
- GroupMe.configure do |config|
29
- config.access_token = 'ax7snqkoRiJ0yGPsbKSgeBnBEtqeSkALMC2qJPrT'
30
- end
28
+ require 'groupme'
29
+
30
+ client = GroupMe::Client.new(
31
+ access_token: 'ax7snqkoRiJ0yGPsbKSgeBnBEtqeSkALMC2qJPrT'
32
+ )
31
33
  ```
32
34
 
33
35
  ## Usage
@@ -35,14 +37,14 @@ end
35
37
  #### Get All Groups
36
38
 
37
39
  ```ruby
38
- response = GroupMe::Request.new(:get, 'groups').send
39
- puts response.body
40
+ response, status = client.get('groups')
41
+ puts response
40
42
  ```
41
43
 
42
44
 
43
45
  #### Create A Group
44
46
 
45
47
  ```ruby
46
- response = GroupMe::Request.new(:post, 'groups', name: 'Test Group').send
47
- puts response.body
48
+ response, status = client.post('groups', name: 'New Group')
49
+ puts response
48
50
  ```
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'rake', '~> 10.0'
27
27
  spec.add_development_dependency 'rspec', '~> 3.8'
28
28
  spec.add_development_dependency 'simplecov', '~> 0.15'
29
- spec.add_development_dependency 'sinatra', '~> 2.0'
30
- spec.add_development_dependency 'sinatra-contrib', '~> 2.0'
29
+ spec.add_development_dependency 'vcr', '~> 4.0'
31
30
  spec.add_development_dependency 'webmock', '~> 3.4'
32
31
  end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'groupme'
@@ -3,25 +3,8 @@
3
3
  require 'httpclient'
4
4
  require 'json'
5
5
 
6
- require 'groupme/configuration'
7
- require 'groupme/group'
8
- require 'groupme/response'
9
- require 'groupme/request'
6
+ require 'groupme/client'
10
7
  require 'groupme/version'
11
8
 
12
9
  module GroupMe
13
- class << self
14
- def configuration
15
- @configuration ||= Configuration.new
16
- end
17
- end
18
-
19
- def self.configure
20
- self.configuration ||= Configuration.new
21
- yield(configuration)
22
- end
23
-
24
- def self.reset!
25
- @configuration = Configuration.new
26
- end
27
10
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GroupMe
4
+ class Client
5
+ API_BASE_URL = 'https://api.groupme.com/v3/'
6
+ API_DEFAULT_HEADER = { 'Content-Type': 'application/json' }.freeze
7
+
8
+ def initialize(access_token:)
9
+ @access_token = access_token
10
+ @client = HTTPClient.new(base_url: API_BASE_URL, default_header: API_DEFAULT_HEADER)
11
+ end
12
+
13
+ def request(method, path, query: {}, body: {})
14
+ response = @client.request(method, path, { token: @access_token }.merge(query), body.to_json)
15
+ [parse_response_body(response), response.status]
16
+ end
17
+
18
+ def get(path, query = {})
19
+ request(:get, path, query: query)
20
+ end
21
+
22
+ def post(path, body = {})
23
+ request(:post, path, body: body)
24
+ end
25
+
26
+ def delete(path, query = {})
27
+ request(:delete, path, query: query)
28
+ end
29
+
30
+ private
31
+
32
+ def parse_response_body(response)
33
+ return response.reason unless response.ok?
34
+
35
+ JSON.parse(response.body, symbolize_names: true).fetch(:response)
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GroupMe
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'groupme'
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe GroupMe::Client do
4
+ let(:client) { GroupMe::Client.new(access_token: ACCESS_TOKEN) }
5
+ let(:base_url) { 'https://api.groupme.com/v3/' }
6
+
7
+ describe '.new' do
8
+ context 'when :access_token argument is missing' do
9
+ it 'should raise an error' do
10
+ expect { GroupMe::Client.new }.to raise_error(ArgumentError)
11
+ end
12
+ end
13
+
14
+ context 'when :access_token is set' do
15
+ it 'should not raise an error' do
16
+ expect { GroupMe::Client.new(access_token: ACCESS_TOKEN) }.not_to raise_error
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#request' do
22
+ let(:stubbed_data) { { id: 1, name: 'Group' } }
23
+ let(:stubbed_response_body) { { response: stubbed_data }.to_json }
24
+ let(:stubbed_response_status) { 200 }
25
+
26
+ before do
27
+ stub_request(:any, /api.groupme.com/).to_return(
28
+ body: stubbed_response_body,
29
+ status: stubbed_response_status
30
+ )
31
+ end
32
+
33
+ context 'when there are no parameters' do
34
+ it 'should send the correct HTTP request' do
35
+ client.request(:get, 'groups')
36
+
37
+ expect(WebMock).to have_requested(:get, "#{base_url}groups").with(query: { token: ACCESS_TOKEN })
38
+ end
39
+ end
40
+
41
+ context 'when there are query parameters' do
42
+ it 'should send the correct HTTP request' do
43
+ client.request(:get, 'groups', query: { per_page: 1 })
44
+
45
+ expect(WebMock).to have_requested(:get, "#{base_url}groups").with(query: { token: ACCESS_TOKEN, per_page: 1 })
46
+ end
47
+ end
48
+
49
+ context 'when there are body parameters' do
50
+ it 'should send the correct HTTP request' do
51
+ client.request(:post, 'groups', body: { name: 'Group' })
52
+
53
+ expect(WebMock).to have_requested(:post, "#{base_url}groups?token=#{ACCESS_TOKEN}").with(body: { name: 'Group' }.to_json)
54
+ end
55
+ end
56
+
57
+ context 'when response is successful' do
58
+ let(:stubbed_response_body) { { response: stubbed_data }.to_json }
59
+ let(:stubbed_response_status) { 201 }
60
+
61
+ it 'should parse and return the response' do
62
+ response, _status = client.request(:post, 'groups')
63
+
64
+ expect(response).to eq(stubbed_data)
65
+ end
66
+
67
+ it 'should return the successful status code' do
68
+ _response, status = client.request(:post, 'groups')
69
+
70
+ expect(status).to eq(201)
71
+ end
72
+ end
73
+
74
+ context 'when response is unsuccessful' do
75
+ let(:stubbed_response_body) { '' }
76
+ let(:stubbed_response_status) { [404, 'Not Found'] }
77
+
78
+ it 'should return the response reason' do
79
+ response, _status = client.request(:post, 'groups')
80
+
81
+ expect(response).to eq('Not Found')
82
+ end
83
+
84
+ it 'should return the unsuccesful status code' do
85
+ _response, status = client.request(:post, 'groups')
86
+
87
+ expect(status).to eq(404)
88
+ end
89
+ end
90
+ end
91
+
92
+ describe '#get' do
93
+ let(:stubbed_data) { { id: 1, name: 'Group' } }
94
+ let(:stubbed_response_code) { 200 }
95
+
96
+ before do
97
+ stub_request(:get, /api.groupme.com/).to_return(
98
+ body: { response: stubbed_data }.to_json,
99
+ status: stubbed_response_code
100
+ )
101
+ end
102
+
103
+ it 'should parse and return the response' do
104
+ response, _status = client.get('groups', per_page: 1)
105
+
106
+ expect(response).to eq(stubbed_data)
107
+ end
108
+
109
+ it 'should return the status code' do
110
+ _response, status = client.get('groups', per_page: 1)
111
+
112
+ expect(status).to eq(stubbed_response_code)
113
+ end
114
+ end
115
+
116
+ describe '#post' do
117
+ let(:stubbed_data) { { id: 1, name: 'Group' } }
118
+ let(:stubbed_response_code) { 200 }
119
+
120
+ before do
121
+ stub_request(:post, /api.groupme.com/).to_return(
122
+ body: { response: stubbed_data }.to_json,
123
+ status: stubbed_response_code
124
+ )
125
+ end
126
+
127
+ it 'should parse and return the response' do
128
+ response, _status = client.post('groups', name: 'Group')
129
+
130
+ expect(response).to eq(stubbed_data)
131
+ end
132
+
133
+ it 'should return the status code' do
134
+ _response, status = client.post('groups', name: 'Group')
135
+
136
+ expect(status).to eq(stubbed_response_code)
137
+ end
138
+ end
139
+
140
+ describe '#delete' do
141
+ let(:stubbed_data) { 'OK' }
142
+ let(:stubbed_response_code) { 200 }
143
+
144
+ before do
145
+ stub_request(:delete, /api.groupme.com/).to_return(
146
+ body: { response: stubbed_data }.to_json,
147
+ status: stubbed_response_code
148
+ )
149
+ end
150
+
151
+ it 'should parse and return the response' do
152
+ response, _status = client.delete('groups', id: 1)
153
+
154
+ expect(response).to eq(stubbed_data)
155
+ end
156
+
157
+ it 'should return the status code' do
158
+ _response, status = client.delete('groups', id: 1)
159
+
160
+ expect(status).to eq(stubbed_response_code)
161
+ end
162
+ end
163
+ end
@@ -2,27 +2,16 @@
2
2
 
3
3
  require 'simplecov'
4
4
  require 'coveralls'
5
- require 'webmock'
6
5
 
7
6
  SimpleCov.start
8
7
  Coveralls.wear!
9
- WebMock.enable!
10
8
 
11
- require 'bundler/setup'
12
9
  require 'groupme'
13
- require 'support/fake_groupme'
14
- require 'securerandom'
15
10
 
16
- RSpec.configure do |config|
17
- include WebMock::API
11
+ require 'support/groupme'
12
+ require 'support/vcr'
13
+ require 'support/webmock'
18
14
 
15
+ RSpec.configure do |config|
19
16
  config.filter_run_when_matching :focus
20
-
21
- config.expect_with :rspec do |c|
22
- c.syntax = :expect
23
- end
24
-
25
- config.before(:each) do
26
- stub_request(:any, /api.groupme.com/).to_rack(FakeGroupMe)
27
- end
28
17
  end