shift_planning_client 0.0.4 → 0.0.5
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/README.md +19 -1
- data/lib/shift_planning.rb +1 -0
- data/lib/shift_planning/api_error.rb +2 -0
- data/lib/shift_planning/authentication_keeper.rb +28 -0
- data/lib/shift_planning/connection.rb +4 -0
- data/lib/shift_planning/version.rb +1 -1
- data/shift_planning.gemspec +1 -1
- data/spec/authentication_keeper_spec.rb +25 -0
- data/spec/client_spec.rb +3 -3
- data/spec/spec_helper.rb +4 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a5cd44b86aedbb0320a4c776642b7a4a9354d31
|
4
|
+
data.tar.gz: 10e18af9854af65f905c3f21df8a9e389a86a5bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c77cb32176ceb63e29ad56aba6fc25159645eb6403ce5555765322dd6df089d67ace899efb982513d799c44ce7e5893a99f0f6b114cca2d193b700d21e72b97
|
7
|
+
data.tar.gz: c9368998487139c022a47caebc83ee30979f889fc1c7da15a0aee36ee8c4e65724d403944b43b13159cd5d4baf16a2aea96c6d1b1dec30faf2dcd4e8f211f375
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Ruby client gem for http://www.shiftplanning.com
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem '
|
9
|
+
gem 'shift_planning_client'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -34,6 +34,18 @@ client.<api_namespace>.<method>_<endpoint>(required_arg_1, required_arg_2 [, opt
|
|
34
34
|
client.staff.get_logout
|
35
35
|
```
|
36
36
|
|
37
|
+
or
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
shift_planning = ShiftPlanning::AuthenticationKeeper.new('api_key', 'username', 'password')
|
41
|
+
shift_planning.run do |c|
|
42
|
+
c.timeclock.get_clockin()
|
43
|
+
|
44
|
+
...
|
45
|
+
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
37
49
|
Rescue from api errors with:
|
38
50
|
|
39
51
|
```ruby
|
@@ -46,6 +58,12 @@ Rescue from api errors with:
|
|
46
58
|
Api map described in lib/shift_planning/client.rb
|
47
59
|
For more info follow http://www.shiftplanning.com/api/
|
48
60
|
|
61
|
+
To run specs:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
SHIFT_PLANNING_KEY='key' SHIFT_PLANNING_STAFF_USERNAME='username' SHIFT_PLANNING_STAFF_PASSWORD='password' rspec spec
|
65
|
+
```
|
66
|
+
|
49
67
|
## Contributing
|
50
68
|
|
51
69
|
1. Fork it ( http://github.com/AskarZinurov/shift_planning/fork )
|
data/lib/shift_planning.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
class ShiftPlanning::AuthenticationKeeper
|
2
|
+
attr_reader :client
|
3
|
+
|
4
|
+
def initialize(api_key, username, password)
|
5
|
+
@client = ShiftPlanning::Client.new(api_key)
|
6
|
+
@username = username
|
7
|
+
@password = password
|
8
|
+
end
|
9
|
+
|
10
|
+
def run(&block)
|
11
|
+
login unless @client.connection.authenticated?
|
12
|
+
block.call @client
|
13
|
+
rescue ShiftPlanning::ApiError => e
|
14
|
+
raise e if e.code != 3
|
15
|
+
login
|
16
|
+
block.call @client
|
17
|
+
end
|
18
|
+
|
19
|
+
def logout
|
20
|
+
@client.staff.get_logout if @client.connection.authenticated?
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def login
|
26
|
+
@client.staff.get_login(@username, @password)
|
27
|
+
end
|
28
|
+
end
|
data/shift_planning.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.5"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.4"
|
23
|
-
spec.add_development_dependency "rspec", "~> 3.1
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.1"
|
24
24
|
|
25
25
|
spec.add_runtime_dependency 'faraday', "~> 0.9"
|
26
26
|
spec.add_runtime_dependency 'faraday_middleware', "~> 0.9.1"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ShiftPlanning::AuthenticationKeeper do
|
4
|
+
let(:client_stub) { double(connection: '', staff: '') }
|
5
|
+
|
6
|
+
subject(:client) { described_class.new('key', 'username', 'password') }
|
7
|
+
|
8
|
+
before do
|
9
|
+
client.instance_variable_set '@client', client_stub
|
10
|
+
allow(client_stub.connection).to receive(:authenticated?) { true }
|
11
|
+
allow(client_stub.staff).to receive(:get_login) { true }
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should catch expired token error' do
|
15
|
+
expect(client).to receive(:login) { true }
|
16
|
+
results = [ ->(c) { true }, ->(c) { raise(ShiftPlanning::ApiError.parse(3)) }]
|
17
|
+
client.run { |c| results.pop.call(c) }
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should raise api error' do
|
21
|
+
expect do
|
22
|
+
client.run { |c| raise(ShiftPlanning::ApiError.parse(3)) }
|
23
|
+
end.to raise_error(ShiftPlanning::ApiError)
|
24
|
+
end
|
25
|
+
end
|
data/spec/client_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ShiftPlanning::Client do
|
4
4
|
context 'staff' do
|
@@ -18,11 +18,11 @@ describe ShiftPlanning::Client do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should return skills' do
|
21
|
-
client.staff.get_skills.
|
21
|
+
expect(client.staff.get_skills).to eq('')
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'can logout' do
|
25
|
-
client.staff.get_logout.
|
25
|
+
expect(client.staff.get_logout).to eq('')
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shift_planning_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Askar Zinurov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.1
|
47
|
+
version: '3.1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.1
|
54
|
+
version: '3.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: faraday
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,11 +95,14 @@ files:
|
|
95
95
|
- lib/shift_planning.rb
|
96
96
|
- lib/shift_planning/api_error.rb
|
97
97
|
- lib/shift_planning/api_module.rb
|
98
|
+
- lib/shift_planning/authentication_keeper.rb
|
98
99
|
- lib/shift_planning/client.rb
|
99
100
|
- lib/shift_planning/connection.rb
|
100
101
|
- lib/shift_planning/version.rb
|
101
102
|
- shift_planning.gemspec
|
103
|
+
- spec/authentication_keeper_spec.rb
|
102
104
|
- spec/client_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
103
106
|
homepage: https://github.com/AskarZinurov/shift_planning
|
104
107
|
licenses:
|
105
108
|
- MIT
|
@@ -125,4 +128,6 @@ signing_key:
|
|
125
128
|
specification_version: 4
|
126
129
|
summary: Client library to www.shiftplanning.com
|
127
130
|
test_files:
|
131
|
+
- spec/authentication_keeper_spec.rb
|
128
132
|
- spec/client_spec.rb
|
133
|
+
- spec/spec_helper.rb
|