shift_planning 0.0.3 → 1.0.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 +4 -4
- data/lib/shift_planning/api_error.rb +39 -0
- data/lib/shift_planning/client.rb +7 -4
- data/lib/shift_planning/version.rb +1 -1
- data/test/unit/api_error_test.rb +37 -0
- data/test/unit/client_test.rb +2 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d9d965889cdec208eaa3b63d9a0d106a2492aae
|
4
|
+
data.tar.gz: 082ba58213165e24381c22e319b9f8851d142c72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b994e218f879a8d8546291baff43c6daf40054613e206aa586391653ccb61124506e13610566745881b438acc4c03f5db5e59d437bb36f66a92d8e073fa2c35
|
7
|
+
data.tar.gz: 7b7d62e28efe2f356fa95be08baa19a99ec4f45cf4c20bc0d9af36691d0e7b9afe98fb2fdbcc304b25b76ac89935a982678b8ee13ad865008b4344f6eacee099
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module ShiftPlanning
|
2
|
+
class ApiError < Exception
|
3
|
+
attr_accessor :message
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@message = message_for_status(response["status"])
|
7
|
+
end
|
8
|
+
|
9
|
+
def message_for_status(status)
|
10
|
+
case status
|
11
|
+
when "-3" then "Flagged API Key - Pemanently Banned"
|
12
|
+
when "-2" then "Flagged API Key - Too Many invalid access attempts - contact us"
|
13
|
+
when "-1" then "Flagged API Key - Temporarily Disabled - contact us"
|
14
|
+
when "1" then "Success -"
|
15
|
+
when "2" then "Invalid API key - App must be granted a valid key by ShiftPlanning"
|
16
|
+
when "3" then "Invalid token key - Please re-authenticate"
|
17
|
+
when "4" then "Invalid Method - No Method with that name exists in our API"
|
18
|
+
when "5" then "Invalid Module - No Module with that name exists in our API"
|
19
|
+
when "6" then "Invalid Action - No Action with that name exists in our API"
|
20
|
+
when "7" then "Authentication Failed - You do not have permissions to access the service"
|
21
|
+
when "8" then "Missing parameters - Your request is missing a required parameter"
|
22
|
+
when "9" then "Invalid parameters - Your request has an invalid parameter type"
|
23
|
+
when "10" then "Extra parameters - Your request has an extra/unallowed parameter type"
|
24
|
+
when "12" then "Create Failed - Your CREATE request failed"
|
25
|
+
when "13" then "Update Failed - Your UPDATE request failed"
|
26
|
+
when "14" then "Delete Failed - Your DELETE request failed"
|
27
|
+
when "15" then "Get Failed - Your GET request failed"
|
28
|
+
when "20" then "Incorrect Permissions - You don't have the proper permissions to access this"
|
29
|
+
when "90" then "Suspended API key - Access for your account has been suspended, please contact ShiftPlanning"
|
30
|
+
when "91" then "Throttle exceeded - You have exceeded the max allowed requests. Try again later."
|
31
|
+
when "98" then "Bad API Paramaters - Invalid POST request. See Manual."
|
32
|
+
when "99" then "Service Offline - This service is temporarily offline. Try again later."
|
33
|
+
when "100" then "Can not connect to LDAP - host or port are incorect"
|
34
|
+
when "101" then "Can not connect to LDAP - username or password are incorrect"
|
35
|
+
else "Unknown status response: #{status}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "http"
|
2
|
+
require "json"
|
3
|
+
require "base64"
|
4
|
+
require_relative "api_error"
|
4
5
|
|
5
6
|
module ShiftPlanning
|
6
7
|
class Client
|
@@ -63,7 +64,9 @@ module ShiftPlanning
|
|
63
64
|
"request" => request
|
64
65
|
})
|
65
66
|
response = HTTP.with(@headers).post(@url, body)
|
66
|
-
JSON.parse(response)
|
67
|
+
result = JSON.parse(response)
|
68
|
+
raise ApiError.new(result) if result["status"] != "1"
|
69
|
+
result
|
67
70
|
end
|
68
71
|
|
69
72
|
def body_formatter(body)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'ApiError' do
|
4
|
+
describe '#constructor' do
|
5
|
+
def check(status, message)
|
6
|
+
error = ShiftPlanning::ApiError.new("status" => status)
|
7
|
+
assert_equal message, error.message
|
8
|
+
end
|
9
|
+
|
10
|
+
it "handles api status" do
|
11
|
+
check("-3", "Flagged API Key - Pemanently Banned")
|
12
|
+
check("-2", "Flagged API Key - Too Many invalid access attempts - contact us")
|
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
|
36
|
+
end
|
37
|
+
end
|
data/test/unit/client_test.rb
CHANGED
@@ -46,7 +46,7 @@ describe 'Client' do
|
|
46
46
|
it 'authenticates and makes api request' 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
|
-
.to_return(:status => 200, :body => "{\"id\":\"1\"}", :headers => {})
|
49
|
+
.to_return(:status => 200, :body => "{\"status\":\"1\", \"id\":\"1\"}", :headers => {})
|
50
50
|
employee = @client.get('staff.employee', "id" => 1)
|
51
51
|
assert 1, employee[:id]
|
52
52
|
end
|
@@ -56,7 +56,7 @@ describe 'Client' do
|
|
56
56
|
it 'authenticates and makes api request' do
|
57
57
|
stub_request(:post, "http://www.shiftplanning.com/api/")
|
58
58
|
.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'})
|
59
|
-
.to_return(:status => 200, :body => "{\"id\":\"1\"}", :headers => {})
|
59
|
+
.to_return(:status => 200, :body => "{\"status\":\"1\", \"id\":\"1\"}", :headers => {})
|
60
60
|
|
61
61
|
employee = @client.update('staff.employee', {
|
62
62
|
"id" => 1,
|
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: 0.0
|
4
|
+
version: 1.0.0
|
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-02-
|
11
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -95,10 +95,12 @@ files:
|
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
97
|
- lib/shift_planning.rb
|
98
|
+
- lib/shift_planning/api_error.rb
|
98
99
|
- lib/shift_planning/client.rb
|
99
100
|
- lib/shift_planning/version.rb
|
100
101
|
- shift_planning.gemspec
|
101
102
|
- test/test_helper.rb
|
103
|
+
- test/unit/api_error_test.rb
|
102
104
|
- test/unit/client_test.rb
|
103
105
|
homepage: ''
|
104
106
|
licenses:
|
@@ -126,4 +128,5 @@ specification_version: 4
|
|
126
128
|
summary: Shift Planning API gem
|
127
129
|
test_files:
|
128
130
|
- test/test_helper.rb
|
131
|
+
- test/unit/api_error_test.rb
|
129
132
|
- test/unit/client_test.rb
|