groupme-api 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,43 +0,0 @@
1
- {
2
- "id": "44835902",
3
- "group_id": "44835902",
4
- "name": "Family Group",
5
- "phone_number": "+1 6193780416",
6
- "type": "private",
7
- "description": null,
8
- "image_url": null,
9
- "creator_user_id": "3193012",
10
- "created_at": 1538721837,
11
- "updated_at": 1538721837,
12
- "office_mode": false,
13
- "share_url": null,
14
- "share_qr_code_url": null,
15
- "members": [
16
- {
17
- "id": "384075821",
18
- "user_id": "3193012",
19
- "nickname": "Test Account",
20
- "muted": false,
21
- "image_url": null,
22
- "autokicked": false,
23
- "roles": [
24
- "admin",
25
- "owner"
26
- ],
27
- "name": "Test Account"
28
- }
29
- ],
30
- "max_memberships": 500,
31
- "max_members": 500,
32
- "messages": {
33
- "count": 0,
34
- "last_message_id": null,
35
- "last_message_created_at": null,
36
- "preview": {
37
- "nickname": null,
38
- "text": null,
39
- "image_url": null,
40
- "attachments": []
41
- }
42
- }
43
- }
@@ -1,42 +0,0 @@
1
- {
2
- "id": "44835935",
3
- "group_id": "44835935",
4
- "name": "Gaming Group",
5
- "phone_number": "+1 3363554142",
6
- "type": "private",
7
- "description": "",
8
- "image_url": null,
9
- "creator_user_id": "3193012",
10
- "created_at": 1538722180,
11
- "updated_at": 1538722180,
12
- "office_mode": false,
13
- "share_url": null,
14
- "share_qr_code_url": null,
15
- "members": [
16
- {
17
- "user_id": "3193012",
18
- "nickname": "Test Account",
19
- "image_url": null,
20
- "id": "384076097",
21
- "muted": false,
22
- "autokicked": false,
23
- "roles": [
24
- "admin",
25
- "owner"
26
- ],
27
- "name": "Test Account"
28
- }
29
- ],
30
- "messages": {
31
- "count": 0,
32
- "last_message_id": "",
33
- "last_message_created_at": 0,
34
- "preview": {
35
- "nickname": null,
36
- "text": null,
37
- "image_url": null,
38
- "attachments": []
39
- }
40
- },
41
- "max_members": 500
42
- }
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe GroupMe::Configuration do
4
- after(:each) { GroupMe.reset! }
5
-
6
- context 'when access token is not set' do
7
- it 'should not raise an error' do
8
- expect { GroupMe.configuration.access_token }.not_to raise_error
9
- end
10
-
11
- it 'should return nil' do
12
- expect(GroupMe.configuration.access_token).to eq(nil)
13
- end
14
- end
15
-
16
- context 'when access token is set' do
17
- let(:access_token) { SecureRandom.base64(30) }
18
-
19
- before do
20
- GroupMe.configure { |config| config.access_token = access_token }
21
- end
22
-
23
- it 'should return it' do
24
- expect(GroupMe.configuration.access_token).to eq(access_token)
25
- end
26
- end
27
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe GroupMe::Group do
4
- describe '#all' do
5
- end
6
- end
@@ -1,130 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe GroupMe::Request do
4
- let(:access_token) { SecureRandom.base64(30) }
5
-
6
- before do
7
- GroupMe.configure { |config| config.access_token = access_token }
8
- end
9
-
10
- describe '.new' do
11
- let(:request) { GroupMe::Request.new(method, path, opts) }
12
-
13
- context 'when no parameters are set' do
14
- let(:request) { GroupMe::Request.new }
15
-
16
- it 'should use :get as the method' do
17
- expect(request.method).to eq(:get)
18
- end
19
-
20
- it 'should use empty path as the path' do
21
- expect(request.path).to eq('')
22
- end
23
-
24
- it 'should have an empty Hash as opts' do
25
- expect(request.opts).to eq({})
26
- end
27
- end
28
-
29
- context 'when method is not :get, :post, or :delete' do
30
- it 'should raise an error' do
31
- expect { GroupMe::Request.new(:patch) }.to raise_error(GroupMe::UnacceptableRequestMethodError)
32
- end
33
- end
34
- end
35
-
36
- describe '#send' do
37
- let(:request) { GroupMe::Request.new(:get, 'groups') }
38
-
39
- it 'should not return an error' do
40
- expect { request.send }.not_to raise_error
41
- end
42
-
43
- it 'should be get back a GroupMe::Response object' do
44
- response = request.send
45
-
46
- expect(response).to be_an_instance_of(GroupMe::Response)
47
- end
48
- end
49
-
50
- describe '#method' do
51
- let(:request) { GroupMe::Request.new(:delete, 'groups', per_page: 100) }
52
-
53
- it 'should be able to retrieve the method' do
54
- expect(request.method).to eq(:delete)
55
- end
56
- end
57
-
58
- describe '#path' do
59
- let(:request) { GroupMe::Request.new(:delete, 'groups', per_page: 100) }
60
-
61
- it 'should be able to retrieve the path' do
62
- expect(request.path).to eq('groups')
63
- end
64
- end
65
-
66
- describe '#opts' do
67
- let(:request) { GroupMe::Request.new(:delete, 'groups', per_page: 100) }
68
-
69
- it 'should be able to retrieve the opts' do
70
- expect(request.opts).to eq({ per_page: 100 })
71
- end
72
- end
73
-
74
- describe '#full_uri' do
75
- let(:request) { GroupMe::Request.new(:get, 'groups') }
76
- let(:base_uri) { GroupMe::Request::API_BASE_URI }
77
-
78
- it 'should be able to build & return a full uri' do
79
- expect(request.full_uri).to eq("#{base_uri}/groups")
80
- end
81
- end
82
-
83
- describe '#full_opts' do
84
- let(:request) { GroupMe::Request.new(:get, 'groups', opts) }
85
-
86
- context 'when opts are not initially set' do
87
- let(:opts) { {} }
88
-
89
- it 'should return just the token' do
90
- expect(request.full_opts).to eq({ token: access_token })
91
- end
92
- end
93
-
94
- context 'when opts are initially set' do
95
- let(:opts) { { per_page: 100 } }
96
-
97
- it 'should return opts & token' do
98
- expect(request.full_opts).to eq({ token: access_token, per_page: 100 })
99
- end
100
- end
101
-
102
- context 'when one of the opts is a new token' do
103
- let(:new_access_token) { SecureRandom.base64(30) }
104
- let(:opts) { { token: new_access_token, per_page: 100 } }
105
-
106
- it 'should return opts & only the new token' do
107
- expect(request.full_opts).to eq({ token: new_access_token, per_page: 100 })
108
- end
109
- end
110
- end
111
-
112
- describe '#token' do
113
- context 'no token is specified in opts' do
114
- let(:request) { GroupMe::Request.new(:get, 'groups') }
115
-
116
- it 'should use the configured token' do
117
- expect(request.token).to eq(access_token)
118
- end
119
- end
120
-
121
- context 'a different token is specified in opts' do
122
- let(:new_access_token) { SecureRandom.base64(30) }
123
- let(:request) { GroupMe::Request.new(:get, 'groups', token: new_access_token) }
124
-
125
- it 'should use the new token' do
126
- expect(request.token).to eq(new_access_token)
127
- end
128
- end
129
- end
130
- end
@@ -1,64 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe GroupMe::Response do
4
- let(:request) { GroupMe::Request.new(:get, 'groups') }
5
- let(:response) { request.send }
6
-
7
- describe '#new' do
8
- it 'should initialize a GroupMe::Response object' do
9
- expect(response).to be_an_instance_of(GroupMe::Response)
10
- end
11
- end
12
-
13
- describe '.raw' do
14
- it 'should return an HTTP::Response object' do
15
- expect(response.raw).to be_an_instance_of(HTTP::Message)
16
- end
17
- end
18
-
19
- describe '.code' do
20
- let(:actual_code) { response.raw.code }
21
-
22
- it 'should the response status code' do
23
- expect(response.code).to eq(actual_code)
24
- end
25
- end
26
-
27
- describe '.body' do
28
- let(:response_body) { response.body }
29
-
30
- context 'when response will be an array' do
31
- let(:request) { GroupMe::Request.new(:get, 'groups') }
32
-
33
- it 'should parse the JSON response into an Array' do
34
- expect(response_body).to be_an_instance_of(Array)
35
- end
36
-
37
- it 'should symbolize names' do
38
- keys = response_body.first.keys
39
-
40
- expect(keys.all? { |k| k.is_a? Symbol }).to eq(true)
41
- end
42
- end
43
-
44
- context 'when response will be an hash' do
45
- let(:request) { GroupMe::Request.new(:get, 'groups/1234567890') }
46
-
47
- it 'should parse the JSON response into an Hash' do
48
- expect(response_body).to be_an_instance_of(Hash)
49
- end
50
-
51
- it 'should symbolize names' do
52
- expect(response_body.keys.all? { |k| k.is_a? Symbol }).to eq(true)
53
- end
54
-
55
- it 'should not have the key "response"' do
56
- expect(response_body.has_key?(:response)).to eq(false)
57
- end
58
-
59
- it 'should not have the key "meta"' do
60
- expect(response_body.has_key?(:meta)).to eq(false)
61
- end
62
- end
63
- end
64
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'sinatra/base'
4
- require 'sinatra/namespace'
5
-
6
- class FakeGroupMe < Sinatra::Base
7
- register Sinatra::Namespace
8
-
9
- namespace '/v3' do
10
- get '/groups' do
11
- json_response('groups/index', 200)
12
- end
13
-
14
- get '/groups/:group_id' do
15
- json_response('groups/show', 200)
16
- end
17
- end
18
-
19
- private
20
-
21
- def json_response(fixture_path, status_code = 200)
22
- "{\"response\":#{json_response_body(fixture_path)},\"meta\":{\"code\":#{status_code}}}"
23
- end
24
-
25
- def json_response_body(fixture_path)
26
- File.open("#{File.dirname(__dir__)}/fixtures/#{fixture_path}.json").read
27
- end
28
- end