onfleet-ruby 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -0
- data/.rspec +1 -2
- data/.rubocop.yml +26 -0
- data/.rubocop_todo.yml +38 -0
- data/.ruby-version +2 -0
- data/Gemfile +3 -3
- data/Rakefile +10 -0
- data/lib/onfleet-ruby.rb +40 -38
- data/lib/onfleet-ruby/actions/create.rb +6 -3
- data/lib/onfleet-ruby/actions/delete.rb +4 -4
- data/lib/onfleet-ruby/actions/find.rb +8 -6
- data/lib/onfleet-ruby/actions/get.rb +5 -4
- data/lib/onfleet-ruby/actions/list.rb +15 -13
- data/lib/onfleet-ruby/actions/query_metadata.rb +5 -5
- data/lib/onfleet-ruby/actions/save.rb +13 -9
- data/lib/onfleet-ruby/actions/update.rb +4 -4
- data/lib/onfleet-ruby/address.rb +1 -0
- data/lib/onfleet-ruby/admin.rb +2 -1
- data/lib/onfleet-ruby/destination.rb +2 -1
- data/lib/onfleet-ruby/errors/authentication_error.rb +1 -0
- data/lib/onfleet-ruby/errors/connection_error.rb +1 -0
- data/lib/onfleet-ruby/errors/invalid_request_error.rb +1 -0
- data/lib/onfleet-ruby/errors/onfleet_error.rb +1 -0
- data/lib/onfleet-ruby/onfleet_object.rb +58 -59
- data/lib/onfleet-ruby/organization.rb +4 -9
- data/lib/onfleet-ruby/recipient.rb +2 -1
- data/lib/onfleet-ruby/task.rb +4 -4
- data/lib/onfleet-ruby/team.rb +2 -1
- data/lib/onfleet-ruby/util.rb +22 -20
- data/lib/onfleet-ruby/vehicle.rb +1 -0
- data/lib/onfleet-ruby/webhook.rb +2 -2
- data/lib/onfleet-ruby/worker.rb +2 -1
- data/onfleet-ruby.gemspec +11 -6
- data/spec/onfleet/admin_spec.rb +70 -0
- data/spec/onfleet/destination_spec.rb +62 -0
- data/spec/onfleet/organization_spec.rb +25 -0
- data/spec/onfleet/recipient_spec.rb +75 -0
- data/spec/onfleet/task_spec.rb +123 -0
- data/spec/onfleet/team_spec.rb +30 -0
- data/spec/onfleet/webhook_spec.rb +49 -0
- data/spec/onfleet/worker_spec.rb +67 -0
- data/spec/spec_helper.rb +78 -2
- data/spec/support/http_requests/shared_examples.rb +126 -0
- metadata +97 -13
- data/spec/test_data.rb +0 -14
@@ -0,0 +1,126 @@
|
|
1
|
+
RSpec.shared_examples_for "an action that makes a request to Onfleet" do |method:|
|
2
|
+
it "should include the base64-encoded API key in the auth header" do
|
3
|
+
encoded_api_key = Base64.urlsafe_encode64(Onfleet.api_key)
|
4
|
+
|
5
|
+
subject.call
|
6
|
+
expect(
|
7
|
+
a_request(method, url).with(headers: { 'Authorization' => "Basic #{encoded_api_key}" })
|
8
|
+
).to have_been_made.once
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should specify that it will accept JSON" do
|
12
|
+
subject.call
|
13
|
+
expect(
|
14
|
+
a_request(method, url).with(headers: { 'Accept' => 'application/json' })
|
15
|
+
).to have_been_made.once
|
16
|
+
end
|
17
|
+
|
18
|
+
if %i[post put patch].include?(method.to_sym)
|
19
|
+
it "should set the content type to JSON" do
|
20
|
+
subject.call
|
21
|
+
expect(
|
22
|
+
a_request(method, url).with(headers: { 'Content-Type' => 'application/json' })
|
23
|
+
).to have_been_made.once
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "without valid authentication" do
|
28
|
+
let(:response) { { status: 401, body: { message: 'bad auth' }.to_json } }
|
29
|
+
it { should raise_error(Onfleet::AuthenticationError) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "without valid authorization" do
|
33
|
+
let(:response) { { status: 404, body: { message: 'bad auth' }.to_json } }
|
34
|
+
it { should raise_error(Onfleet::InvalidRequestError) }
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when an unspecified error occurs" do
|
38
|
+
let(:response) { { status: 500, body: { message: 'all bad' }.to_json } }
|
39
|
+
it { should raise_error(Onfleet::OnfleetError) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
RSpec.shared_examples_for Onfleet::Actions::Get do |path:|
|
44
|
+
set_up_request_stub(:get, path)
|
45
|
+
let(:response_body) { { id: 'an-object' } }
|
46
|
+
it_should_behave_like "an action that makes a request to Onfleet", method: :get
|
47
|
+
end
|
48
|
+
|
49
|
+
RSpec.shared_examples_for Onfleet::Actions::List do |path:|
|
50
|
+
set_up_request_stub(:get, path)
|
51
|
+
let(:response_body) { [{ id: 'an-object' }, { id: 'another-object' }] }
|
52
|
+
it_should_behave_like "an action that makes a request to Onfleet", method: :get
|
53
|
+
end
|
54
|
+
|
55
|
+
RSpec.shared_examples_for Onfleet::Actions::Create do |path:|
|
56
|
+
set_up_request_stub(:post, path)
|
57
|
+
let(:response_body) { { id: 'an-object' } }
|
58
|
+
|
59
|
+
it_should_behave_like "an action that makes a request to Onfleet", method: :post
|
60
|
+
|
61
|
+
it "should send the object params, not including ID, in JSON" do
|
62
|
+
expected_params = camelize_keys(params.stringify_keys.except('id'))
|
63
|
+
|
64
|
+
subject.call
|
65
|
+
expect(
|
66
|
+
a_request(:post, url).with(body: expected_params.to_json)
|
67
|
+
).to have_been_made.once
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
RSpec.shared_examples_for Onfleet::Actions::Update do |path:|
|
72
|
+
set_up_request_stub(:put, path)
|
73
|
+
let(:response_body) { { id: 'an-object' } }
|
74
|
+
|
75
|
+
it_should_behave_like "an action that makes a request to Onfleet", method: :put
|
76
|
+
|
77
|
+
# The current implementation -- using instance variables -- makes it impossible
|
78
|
+
# to have this example pass deterministically.
|
79
|
+
xit "should send the object params, including ID, in JSON" do
|
80
|
+
expected_params = camelize_keys(params.merge(id: id))
|
81
|
+
|
82
|
+
subject.call
|
83
|
+
expect(
|
84
|
+
a_request(:put, url).with(body: expected_params.to_json)
|
85
|
+
).to have_been_made.once
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
RSpec.shared_examples_for Onfleet::Actions::Delete do |path:|
|
90
|
+
set_up_request_stub(:delete, path)
|
91
|
+
let(:response_body) { '' }
|
92
|
+
|
93
|
+
it_should_behave_like "an action that makes a request to Onfleet", method: :delete
|
94
|
+
end
|
95
|
+
|
96
|
+
RSpec.shared_examples_for Onfleet::Actions::Find do |path:|
|
97
|
+
set_up_request_stub(:get, path)
|
98
|
+
let(:response_body) { { id: 'an-object' } }
|
99
|
+
it_should_behave_like "an action that makes a request to Onfleet", method: :get
|
100
|
+
end
|
101
|
+
|
102
|
+
RSpec.shared_examples_for Onfleet::Actions::QueryMetadata do |path:|
|
103
|
+
set_up_request_stub(:post, path + '/metadata')
|
104
|
+
let(:response_body) { [{ id: 'an-object' }, { id: 'another-object' }] }
|
105
|
+
it_should_behave_like "an action that makes a request to Onfleet", method: :post
|
106
|
+
|
107
|
+
it "should send metadata in JSON" do
|
108
|
+
subject.call
|
109
|
+
expect(
|
110
|
+
a_request(:post, url).with(body: metadata.to_json)
|
111
|
+
).to have_been_made.once
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def set_up_request_stub(method, path)
|
116
|
+
let(:url) { URI.join(Onfleet.base_url, path).to_s }
|
117
|
+
let(:response) { { status: 200, body: response_body.to_json } }
|
118
|
+
before { stub_request(method, url).to_return(response) }
|
119
|
+
end
|
120
|
+
|
121
|
+
def camelize_keys(hash)
|
122
|
+
hash.inject({}) do |accumulator, (key, value)|
|
123
|
+
accumulator.merge(key.camelize(:lower) => value)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onfleet-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Wargnier
|
@@ -10,40 +10,104 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2016-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rest-client
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- - "
|
31
|
+
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
33
|
+
version: '2.0'
|
20
34
|
type: :runtime
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- - "
|
38
|
+
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rspec
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - "~>"
|
32
60
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.3
|
61
|
+
version: '3.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-its
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
34
73
|
- - ">="
|
35
74
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
75
|
+
version: '0'
|
37
76
|
type: :development
|
38
77
|
prerelease: false
|
39
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
40
86
|
requirements:
|
41
87
|
- - "~>"
|
42
88
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
|
89
|
+
version: '0.55'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.55'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
45
109
|
- !ruby/object:Gem::Version
|
46
|
-
version: 3.
|
110
|
+
version: '3.4'
|
47
111
|
description: To interact with Onfleet's API
|
48
112
|
email: nick@stylelend.com
|
49
113
|
executables: []
|
@@ -52,8 +116,12 @@ extra_rdoc_files: []
|
|
52
116
|
files:
|
53
117
|
- ".gitignore"
|
54
118
|
- ".rspec"
|
119
|
+
- ".rubocop.yml"
|
120
|
+
- ".rubocop_todo.yml"
|
121
|
+
- ".ruby-version"
|
55
122
|
- Gemfile
|
56
123
|
- README.md
|
124
|
+
- Rakefile
|
57
125
|
- lib/onfleet-ruby.rb
|
58
126
|
- lib/onfleet-ruby/actions/create.rb
|
59
127
|
- lib/onfleet-ruby/actions/delete.rb
|
@@ -80,8 +148,16 @@ files:
|
|
80
148
|
- lib/onfleet-ruby/webhook.rb
|
81
149
|
- lib/onfleet-ruby/worker.rb
|
82
150
|
- onfleet-ruby.gemspec
|
151
|
+
- spec/onfleet/admin_spec.rb
|
152
|
+
- spec/onfleet/destination_spec.rb
|
153
|
+
- spec/onfleet/organization_spec.rb
|
154
|
+
- spec/onfleet/recipient_spec.rb
|
155
|
+
- spec/onfleet/task_spec.rb
|
156
|
+
- spec/onfleet/team_spec.rb
|
157
|
+
- spec/onfleet/webhook_spec.rb
|
158
|
+
- spec/onfleet/worker_spec.rb
|
83
159
|
- spec/spec_helper.rb
|
84
|
-
- spec/
|
160
|
+
- spec/support/http_requests/shared_examples.rb
|
85
161
|
homepage: http://rubygems.org/gems/onfleet-ruby
|
86
162
|
licenses:
|
87
163
|
- MIT
|
@@ -102,10 +178,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
178
|
version: '0'
|
103
179
|
requirements: []
|
104
180
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.
|
181
|
+
rubygems_version: 2.7.6
|
106
182
|
signing_key:
|
107
183
|
specification_version: 4
|
108
184
|
summary: Onfleet ruby api
|
109
185
|
test_files:
|
186
|
+
- spec/onfleet/admin_spec.rb
|
187
|
+
- spec/onfleet/destination_spec.rb
|
188
|
+
- spec/onfleet/organization_spec.rb
|
189
|
+
- spec/onfleet/recipient_spec.rb
|
190
|
+
- spec/onfleet/task_spec.rb
|
191
|
+
- spec/onfleet/team_spec.rb
|
192
|
+
- spec/onfleet/webhook_spec.rb
|
193
|
+
- spec/onfleet/worker_spec.rb
|
110
194
|
- spec/spec_helper.rb
|
111
|
-
- spec/
|
195
|
+
- spec/support/http_requests/shared_examples.rb
|