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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7294a68657aca437e20331a4fe5497d8d3e58bfc
4
- data.tar.gz: 958543fe3eaa3eabb14ad3448f4deb4e7f76cb0c
3
+ metadata.gz: 1a5cd44b86aedbb0320a4c776642b7a4a9354d31
4
+ data.tar.gz: 10e18af9854af65f905c3f21df8a9e389a86a5bd
5
5
  SHA512:
6
- metadata.gz: 41debc8235e4de3c1801bf0382e8f3b0e039f0b736403b9ce64e98461bc5eb527453d1b5fc8bf469bd3ae6d30a3e5e4d7aa04a5d5b82906c61224d2ac3ea9e3c
7
- data.tar.gz: 221694141bc6c83a17266cce400a7dfa415f842b966a2ddaa6539578140eb5b961445ff40543550826caf7ecd1dd5a275d8a97b80b09b6569ce6b223e7b18722
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 'shift_planning'
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 )
@@ -2,3 +2,4 @@ require "faraday"
2
2
  require "faraday_middleware"
3
3
  require "shift_planning/version"
4
4
  require "shift_planning/client"
5
+ require "shift_planning/authentication_keeper"
@@ -1,4 +1,6 @@
1
1
  class ShiftPlanning::ApiError < Exception
2
+ attr_reader :code
3
+
2
4
  CODES = {
3
5
  -3 => 'Flagged API Key - Pemanently Banned',
4
6
  -2 => 'Flagged API Key - Too Many invalid access attempts - contact us',
@@ -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
@@ -31,6 +31,10 @@ class ShiftPlanning::Connection
31
31
  end
32
32
  end
33
33
 
34
+ def authenticated?
35
+ @token && !@token.empty?
36
+ end
37
+
34
38
  private
35
39
 
36
40
  def parse_data(response_data, &block)
@@ -1,3 +1,3 @@
1
1
  module ShiftPlanning
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -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.7"
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 "shift_planning"
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.should == ''
21
+ expect(client.staff.get_skills).to eq('')
22
22
  end
23
23
 
24
24
  it 'can logout' do
25
- client.staff.get_logout.should == ''
25
+ expect(client.staff.get_logout).to eq('')
26
26
  end
27
27
  end
28
28
  end
@@ -0,0 +1,4 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'shift_planning'
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
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-15 00:00:00.000000000 Z
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.7
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.7
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