shift_planning 1.0.1 → 1.0.2
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 +4 -4
- data/.gitignore +0 -0
- data/.ruby-version +0 -0
- data/.travis.yml +0 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/lib/shift_planning.rb +12 -11
- data/lib/shift_planning/api_error.rb +0 -0
- data/lib/shift_planning/client.rb +10 -23
- data/lib/shift_planning/version.rb +1 -1
- data/shift_planning.gemspec +0 -0
- data/test/test_helper.rb +0 -0
- data/test/unit/api_error_test.rb +29 -31
- data/test/unit/client_test.rb +22 -18
- data/test/unit/shift_planning_test.rb +39 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 336bfa5c60eae23b1b4f90198d2f009cc0a3dd95
|
4
|
+
data.tar.gz: 97642f94520ee1b5ff78516fd4c925fdfc2801e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbe92410be5dd32f5c06a81a4364c3634dad1e4fee96cb77bb406a9a5fe60f007d917df9617bb15b4c2b09518e0b24ffab4515d84bd15cb59f9364b0557b015b
|
7
|
+
data.tar.gz: 49d100494d4b9922e325a9f2bf3789d89f18d0f931e3daa896f0b5e219e8f364e87d8c2b0174cb997a1fd25502220eb4319bad4e1a076a2803ccd42bcd7967c8
|
data/.gitignore
CHANGED
File without changes
|
data/.ruby-version
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
data/lib/shift_planning.rb
CHANGED
@@ -1,52 +1,53 @@
|
|
1
1
|
require "shift_planning/version"
|
2
|
+
require "shift_planning/api_error"
|
2
3
|
require "shift_planning/client"
|
3
4
|
|
4
5
|
module ShiftPlanning
|
5
6
|
extend self
|
6
7
|
|
7
8
|
def init(options={})
|
8
|
-
@@client = Client.new(options)
|
9
|
+
@@client = ShiftPlanning::Client.new(options)
|
9
10
|
end
|
10
11
|
|
11
12
|
def get(api_module, request={})
|
12
|
-
@@client.
|
13
|
+
@@client.request("GET", api_module, request)
|
13
14
|
end
|
14
15
|
|
15
16
|
def create(api_module, request={})
|
16
|
-
@@client.
|
17
|
+
@@client.request("CREATE", api_module, request)
|
17
18
|
end
|
18
19
|
|
19
20
|
def update(api_module, request={})
|
20
|
-
@@client.
|
21
|
+
@@client.request("UPDATE", api_module, request)
|
21
22
|
end
|
22
23
|
|
23
24
|
def delete(api_module, request={})
|
24
|
-
@@client.
|
25
|
+
@@client.request("DELETE", api_module, request)
|
25
26
|
end
|
26
27
|
|
27
|
-
#
|
28
|
+
# convenience methods
|
28
29
|
|
29
30
|
def skills
|
30
|
-
|
31
|
+
get('staff.skills')
|
31
32
|
end
|
32
33
|
|
33
34
|
def employees
|
34
|
-
|
35
|
+
get('staff.employees')
|
35
36
|
end
|
36
37
|
|
37
38
|
def employee(employee_id)
|
38
|
-
|
39
|
+
get('staff.employee', "id" => employee_id)
|
39
40
|
end
|
40
41
|
|
41
42
|
def add_skill(employee_id, skill_id)
|
42
|
-
|
43
|
+
update('staff.employee', {
|
43
44
|
"id" => employee_id,
|
44
45
|
"addskill" => skill_id
|
45
46
|
})
|
46
47
|
end
|
47
48
|
|
48
49
|
def remove_skill(employee_id, skill_id)
|
49
|
-
|
50
|
+
update('staff.employee', {
|
50
51
|
"id" => employee_id,
|
51
52
|
"removeskill" => skill_id
|
52
53
|
})
|
File without changes
|
@@ -1,17 +1,22 @@
|
|
1
1
|
require "http"
|
2
2
|
require "json"
|
3
3
|
require "base64"
|
4
|
-
require_relative "api_error"
|
5
4
|
|
6
5
|
module ShiftPlanning
|
7
6
|
class Client
|
7
|
+
attr_accessor :strict
|
8
|
+
|
8
9
|
def initialize(config = {})
|
9
|
-
raise ArgumentError.new('Missing username') unless config.key?
|
10
|
+
raise ArgumentError.new('Missing username') unless config.key?(:username)
|
10
11
|
@username = config[:username]
|
11
|
-
|
12
|
+
|
13
|
+
raise ArgumentError.new('Missing password') unless config.key?(:password)
|
12
14
|
@password = config[:password]
|
13
|
-
|
15
|
+
|
16
|
+
raise ArgumentError.new('Missing api key') unless config.key?(:key)
|
14
17
|
@key = config[:key]
|
18
|
+
|
19
|
+
@strict = config.key?(:strict) ? config[:strict] : true
|
15
20
|
@url = 'http://www.shiftplanning.com/api/'
|
16
21
|
@headers = {
|
17
22
|
"Content-Type" => "application/x-www-form-urlencoded"
|
@@ -36,24 +41,6 @@ module ShiftPlanning
|
|
36
41
|
@token = JSON.parse(response)["token"]
|
37
42
|
end
|
38
43
|
|
39
|
-
def get(api_module, request={})
|
40
|
-
request("GET", api_module, request)
|
41
|
-
end
|
42
|
-
|
43
|
-
def create(api_module, request={})
|
44
|
-
request("CREATE", api_module, request)
|
45
|
-
end
|
46
|
-
|
47
|
-
def update(api_module, request={})
|
48
|
-
request("UPDATE", api_module, request)
|
49
|
-
end
|
50
|
-
|
51
|
-
def delete(api_module, request={})
|
52
|
-
request("DELETE", api_module, request)
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
44
|
def request(method, api_module, request)
|
58
45
|
authenticate unless authenticated?
|
59
46
|
|
@@ -65,7 +52,7 @@ module ShiftPlanning
|
|
65
52
|
})
|
66
53
|
response = HTTP.with(@headers).post(@url, body)
|
67
54
|
result = JSON.parse(response)
|
68
|
-
raise ApiError.new(result) if is_error_response?
|
55
|
+
raise ApiError.new(result) if @strict && is_error_response?(result)
|
69
56
|
result
|
70
57
|
end
|
71
58
|
|
data/shift_planning.gemspec
CHANGED
File without changes
|
data/test/test_helper.rb
CHANGED
File without changes
|
data/test/unit/api_error_test.rb
CHANGED
@@ -1,37 +1,35 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
describe 'ApiError' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
it "Maps status codes" do
|
5
|
+
assert_status_code(-3, "Flagged API Key - Pemanently Banned")
|
6
|
+
assert_status_code(-2, "Flagged API Key - Too Many invalid access attempts - contact us")
|
7
|
+
assert_status_code(-1, "Flagged API Key - Temporarily Disabled - contact us")
|
8
|
+
assert_status_code(1, "Success -")
|
9
|
+
assert_status_code(2, "Invalid API key - App must be granted a valid key by ShiftPlanning")
|
10
|
+
assert_status_code(3, "Invalid token key - Please re-authenticate")
|
11
|
+
assert_status_code(4, "Invalid Method - No Method with that name exists in our API")
|
12
|
+
assert_status_code(5, "Invalid Module - No Module with that name exists in our API")
|
13
|
+
assert_status_code(6, "Invalid Action - No Action with that name exists in our API")
|
14
|
+
assert_status_code(7, "Authentication Failed - You do not have permissions to access the service")
|
15
|
+
assert_status_code(8, "Missing parameters - Your request is missing a required parameter")
|
16
|
+
assert_status_code(9, "Invalid parameters - Your request has an invalid parameter type")
|
17
|
+
assert_status_code(10, "Extra parameters - Your request has an extra/unallowed parameter type")
|
18
|
+
assert_status_code(12, "Create Failed - Your CREATE request failed")
|
19
|
+
assert_status_code(13, "Update Failed - Your UPDATE request failed")
|
20
|
+
assert_status_code(14, "Delete Failed - Your DELETE request failed")
|
21
|
+
assert_status_code(15, "Get Failed - Your GET request failed")
|
22
|
+
assert_status_code(20, "Incorrect Permissions - You don't have the proper permissions to access this")
|
23
|
+
assert_status_code(90, "Suspended API key - Access for your account has been suspended, please contact ShiftPlanning")
|
24
|
+
assert_status_code(91, "Throttle exceeded - You have exceeded the max allowed requests. Try again later.")
|
25
|
+
assert_status_code(98, "Bad API Paramaters - Invalid POST request. See Manual.")
|
26
|
+
assert_status_code(99, "Service Offline - This service is temporarily offline. Try again later.")
|
27
|
+
assert_status_code(100, "Can not connect to LDAP - host or port are incorect")
|
28
|
+
assert_status_code(101, "Can not connect to LDAP - username or password are incorrect")
|
29
|
+
end
|
9
30
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
check(-1, "Flagged API Key - Temporarily Disabled - contact us")
|
14
|
-
check(1, "Success -")
|
15
|
-
check(2, "Invalid API key - App must be granted a valid key by ShiftPlanning")
|
16
|
-
check(3, "Invalid token key - Please re-authenticate")
|
17
|
-
check(4, "Invalid Method - No Method with that name exists in our API")
|
18
|
-
check(5, "Invalid Module - No Module with that name exists in our API")
|
19
|
-
check(6, "Invalid Action - No Action with that name exists in our API")
|
20
|
-
check(7, "Authentication Failed - You do not have permissions to access the service")
|
21
|
-
check(8, "Missing parameters - Your request is missing a required parameter")
|
22
|
-
check(9, "Invalid parameters - Your request has an invalid parameter type")
|
23
|
-
check(10, "Extra parameters - Your request has an extra/unallowed parameter type")
|
24
|
-
check(12, "Create Failed - Your CREATE request failed")
|
25
|
-
check(13, "Update Failed - Your UPDATE request failed")
|
26
|
-
check(14, "Delete Failed - Your DELETE request failed")
|
27
|
-
check(15, "Get Failed - Your GET request failed")
|
28
|
-
check(20, "Incorrect Permissions - You don't have the proper permissions to access this")
|
29
|
-
check(90, "Suspended API key - Access for your account has been suspended, please contact ShiftPlanning")
|
30
|
-
check(91, "Throttle exceeded - You have exceeded the max allowed requests. Try again later.")
|
31
|
-
check(98, "Bad API Paramaters - Invalid POST request. See Manual.")
|
32
|
-
check(99, "Service Offline - This service is temporarily offline. Try again later.")
|
33
|
-
check(100, "Can not connect to LDAP - host or port are incorect")
|
34
|
-
check(101, "Can not connect to LDAP - username or password are incorrect")
|
35
|
-
end
|
31
|
+
def assert_status_code(status, message)
|
32
|
+
error = ShiftPlanning::ApiError.new("status" => status)
|
33
|
+
assert_equal message, error.message
|
36
34
|
end
|
37
35
|
end
|
data/test/unit/client_test.rb
CHANGED
@@ -8,8 +8,8 @@ describe 'Client' do
|
|
8
8
|
:key => 'e145a81787a46fc24802f1626befb20dcd76fd7b'
|
9
9
|
})
|
10
10
|
stub_request(:post, "http://www.shiftplanning.com/api/")
|
11
|
-
|
12
|
-
|
11
|
+
.with(:body => {"data"=>"{\"key\":\"e145a81787a46fc24802f1626befb20dcd76fd7b\",\"request\":{\"module\":\"staff.login\",\"method\":\"GET\",\"username\":\"devapi\",\"password\":\"password\"}}"}, :headers => {'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'www.shiftplanning.com', 'User-Agent'=>'RubyHTTPGem/0.5.0'})
|
12
|
+
.to_return(:status => 200, :body => "{\"token\":\"1714d482a0f3a5e3472fb51c481dc571fd6724e1\"}", :headers => {})
|
13
13
|
end
|
14
14
|
|
15
15
|
describe '#initialize' do
|
@@ -17,21 +17,21 @@ describe 'Client' do
|
|
17
17
|
err = -> {
|
18
18
|
ShiftPlanning::Client.new(:password => '', :key => '')
|
19
19
|
}.must_raise ArgumentError
|
20
|
-
err.message.must_match
|
20
|
+
err.message.must_match(/username/)
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'password is a required field' do
|
24
24
|
err = -> {
|
25
25
|
ShiftPlanning::Client.new(:username => '', :key => '')
|
26
26
|
}.must_raise ArgumentError
|
27
|
-
err.message.must_match
|
27
|
+
err.message.must_match(/password/)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'key is a required field' do
|
31
31
|
err = -> {
|
32
32
|
ShiftPlanning::Client.new(:username => '', :password => '')
|
33
33
|
}.must_raise ArgumentError
|
34
|
-
err.message.must_match
|
34
|
+
err.message.must_match(/key/)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -42,27 +42,31 @@ describe 'Client' do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
describe '#
|
46
|
-
it 'authenticates and
|
45
|
+
describe '#request' do
|
46
|
+
it 'authenticates and posts request body' do
|
47
47
|
stub_request(:post, "http://www.shiftplanning.com/api/")
|
48
48
|
.with(:body => {"data"=>"{\"token\":\"1714d482a0f3a5e3472fb51c481dc571fd6724e1\",\"method\":\"GET\",\"module\":\"staff.employee\",\"request\":{\"id\":1}}"}, :headers => {'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'www.shiftplanning.com', 'User-Agent'=>'RubyHTTPGem/0.5.0'})
|
49
49
|
.to_return(:status => 200, :body => "{\"status\":1, \"id\":\"1\"}", :headers => {})
|
50
|
-
employee = @client.
|
50
|
+
employee = @client.request('GET', 'staff.employee', "id" => 1)
|
51
51
|
assert 1, employee[:id]
|
52
52
|
end
|
53
|
-
end
|
54
53
|
|
55
|
-
|
56
|
-
it 'authenticates and makes api request' do
|
54
|
+
it 'raises errors on failure code' do
|
57
55
|
stub_request(:post, "http://www.shiftplanning.com/api/")
|
58
|
-
.with(:body => {"data"=>"{\"token\":\"1714d482a0f3a5e3472fb51c481dc571fd6724e1\",\"method\":\"
|
59
|
-
.to_return(:status => 200, :body => "{\"status\":
|
56
|
+
.with(:body => {"data"=>"{\"token\":\"1714d482a0f3a5e3472fb51c481dc571fd6724e1\",\"method\":\"GET\",\"module\":\"staff.employee\",\"request\":{\"id\":1}}"}, :headers => {'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'www.shiftplanning.com', 'User-Agent'=>'RubyHTTPGem/0.5.0'})
|
57
|
+
.to_return(:status => 200, :body => "{\"status\":8}", :headers => {})
|
58
|
+
err = -> {
|
59
|
+
@client.request('GET', 'staff.employee', "id" => 1)
|
60
|
+
}.must_raise ShiftPlanning::ApiError
|
61
|
+
err.message.must_match(/Missing parameters/)
|
62
|
+
end
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
it 'ignores errors when strict is false' do
|
65
|
+
@client.strict = false
|
66
|
+
stub_request(:post, "http://www.shiftplanning.com/api/")
|
67
|
+
.with(:body => {"data"=>"{\"token\":\"1714d482a0f3a5e3472fb51c481dc571fd6724e1\",\"method\":\"GET\",\"module\":\"staff.employee\",\"request\":{\"id\":1}}"}, :headers => {'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'www.shiftplanning.com', 'User-Agent'=>'RubyHTTPGem/0.5.0'})
|
68
|
+
.to_return(:status => 200, :body => "{\"status\":8}", :headers => {})
|
69
|
+
@client.request('GET', 'staff.employee', "id" => 1)
|
66
70
|
end
|
67
71
|
end
|
68
72
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'ShiftPlanning' do
|
4
|
+
before do
|
5
|
+
ShiftPlanning.init({
|
6
|
+
:strict => false,
|
7
|
+
:username => 'devapi',
|
8
|
+
:password => 'password',
|
9
|
+
:key => 'e145a81787a46fc24802f1626befb20dcd76fd7b'
|
10
|
+
})
|
11
|
+
stub_request(:post, "http://www.shiftplanning.com/api/")
|
12
|
+
.with(:body => {"data"=>"{\"key\":\"e145a81787a46fc24802f1626befb20dcd76fd7b\",\"request\":{\"module\":\"staff.login\",\"method\":\"GET\",\"username\":\"devapi\",\"password\":\"password\"}}"}, :headers => {'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'www.shiftplanning.com', 'User-Agent'=>'RubyHTTPGem/0.5.0'})
|
13
|
+
.to_return(:status => 200, :body => "{\"token\":\"1714d482a0f3a5e3472fb51c481dc571fd6724e1\"}", :headers => {})
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#get' do
|
17
|
+
it 'authenticates and makes api request' do
|
18
|
+
stub_request(:post, "http://www.shiftplanning.com/api/")
|
19
|
+
.with(:body => {"data"=>"{\"token\":\"1714d482a0f3a5e3472fb51c481dc571fd6724e1\",\"method\":\"GET\",\"module\":\"staff.employee\",\"request\":{\"id\":1}}"}, :headers => {'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'www.shiftplanning.com', 'User-Agent'=>'RubyHTTPGem/0.5.0'})
|
20
|
+
.to_return(:status => 200, :body => "{\"status\":1, \"id\":\"1\"}", :headers => {})
|
21
|
+
employee = ShiftPlanning.get('staff.employee', "id" => 1)
|
22
|
+
assert 1, employee[:id]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#update' do
|
27
|
+
it 'authenticates and makes api request' do
|
28
|
+
stub_request(:post, "http://www.shiftplanning.com/api/")
|
29
|
+
.with(:body => {"data"=>"{\"token\":\"1714d482a0f3a5e3472fb51c481dc571fd6724e1\",\"method\":\"UPDATE\",\"module\":\"staff.employee\",\"request\":{\"id\":1,\"addskill\":2}}"}, :headers => {'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'www.shiftplanning.com', 'User-Agent'=>'RubyHTTPGem/0.5.0'})
|
30
|
+
.to_return(:status => 200, :body => "{\"status\":1, \"id\":\"1\"}", :headers => {})
|
31
|
+
|
32
|
+
employee = ShiftPlanning.update('staff.employee', {
|
33
|
+
"id" => 1,
|
34
|
+
"addskill" => 2
|
35
|
+
})
|
36
|
+
assert 1, employee[:id]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shift_planning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Mercier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- test/test_helper.rb
|
103
103
|
- test/unit/api_error_test.rb
|
104
104
|
- test/unit/client_test.rb
|
105
|
+
- test/unit/shift_planning_test.rb
|
105
106
|
homepage: ''
|
106
107
|
licenses:
|
107
108
|
- MIT
|
@@ -130,3 +131,4 @@ test_files:
|
|
130
131
|
- test/test_helper.rb
|
131
132
|
- test/unit/api_error_test.rb
|
132
133
|
- test/unit/client_test.rb
|
134
|
+
- test/unit/shift_planning_test.rb
|