shift_planning_client 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a00b22e1642429521f5103c7eaf0e20ae3993cfe
4
+ data.tar.gz: 78bb7a25952d05fe37219418abbc968b086249ea
5
+ SHA512:
6
+ metadata.gz: 53996b6f0d27c1d7b508bb1146ef2306ef0f28239192059dcfdb58d6ef7395ddd3d2ad7196e74df740ff8932b414f54077c456a59b91e7353da54689bedb0787
7
+ data.tar.gz: 4e3d55892480d541e614a640b0592217fa00b2adaf9536118426c7d160e1cde5f584fbd6df932d76a75a74caedfbf3668b86899e29c2775cfe83d94e9a0cd20b
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Askar Zinurov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # ShiftPlanning
2
+
3
+ Ruby client gem for http://www.shiftplanning.com
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'shift_planning'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install shift_planning
18
+
19
+ ## Usage
20
+
21
+ Call client.<api_namespace>.<method>_<endpoint>(required_arg_1, required_arg_2 [, optional_params_hash])
22
+
23
+ ```ruby
24
+ client = ShiftPlanning::Client.new(your_api_key)
25
+ client.staff.get_login(username, password, { remember: 1 })
26
+ client.api.get_methods
27
+
28
+ ...
29
+
30
+ client.staff.get_logout
31
+ ```
32
+
33
+ Rescue from api errors with:
34
+
35
+ ```ruby
36
+ begin
37
+ ...
38
+ rescue ShiftPlanning::ApiError => e
39
+ ...
40
+ end
41
+ ```
42
+ For more info follow http://www.shiftplanning.com/api/
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( http://github.com/AskarZinurov/shift_planning/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,37 @@
1
+ class ShiftPlanning::ApiError < Exception
2
+ CODES = {
3
+ -3 => 'Flagged API Key - Pemanently Banned',
4
+ -2 => 'Flagged API Key - Too Many invalid access attempts - contact us',
5
+ -1 => 'Flagged API Key - Temporarily Disabled - contact us',
6
+ 1 => 'Success',
7
+ 2 => 'Invalid API key - App must be granted a valid key by ShiftPlanning',
8
+ 3 => 'Invalid token key - Please re-authenticate',
9
+ 4 => 'Invalid Method - No Method with that name exists in our API',
10
+ 5 => 'Invalid Module - No Module with that name exists in our API',
11
+ 6 => 'Invalid Action - No Action with that name exists in our API',
12
+ 7 => 'Authentication Failed - You do not have permissions to access the service',
13
+ 8 => 'Missing parameters - Your request is missing a required parameter',
14
+ 9 => 'Invalid parameters - Your request has an invalid parameter type',
15
+ 10 => 'Extra parameters - Your request has an extra/unallowed parameter type',
16
+ 12 => 'Create Failed - Your CREATE request failed',
17
+ 13 => 'Update Failed - Your UPDATE request failed',
18
+ 14 => 'Delete Failed - Your DELETE request failed',
19
+ 15 => 'Get Failed - Your GET request failed',
20
+ 20 => 'Incorrect Permissions - You don\'t have the proper permissions to access this',
21
+ 90 => 'Suspended API key - Access for your account has been suspended, please contact ShiftPlanning',
22
+ 91 => 'Throttle exceeded - You have exceeded the max allowed requests. Try again later.',
23
+ 98 => 'Bad API Paramaters - Invalid POST request. See Manual.',
24
+ 99 => 'Service Offline - This service is temporarily offline. Try again later.',
25
+ 100 => 'Can not connect to LDAP - host or port are incorect',
26
+ 101 => 'Can not connect to LDAP - username or password are incorrect'
27
+ }
28
+
29
+ def initialize(code, message)
30
+ @code = code
31
+ super message
32
+ end
33
+
34
+ def self.parse(code)
35
+ raise new(code, CODES[code]) if code != 1
36
+ end
37
+ end
@@ -0,0 +1,24 @@
1
+ class ShiftPlanning::ApiModule
2
+ attr_reader :name
3
+
4
+ def initialize(connection, name)
5
+ @name = name
6
+ @connection = connection
7
+ end
8
+
9
+ class << self
10
+ %w[get create update delete].each do |method|
11
+ define_method(method) do |endpoint, params = []|
12
+ define_method("#{ method }_#{ endpoint }") do |*args|
13
+ if params.length > args.length
14
+ raise ArgumentError.new("Wrong number of arguments (#{ args.length } for #{ params.length })")
15
+ end
16
+ params_hash = {}
17
+ params.each_with_index { |p, i| params_hash[p] = args[i] }
18
+ params_hash = args[params.length].merge(params_hash) if args[params.length]
19
+ @connection.call(method.upcase, "#{ name }.#{ endpoint }", params_hash)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,207 @@
1
+ require 'shift_planning/api_error'
2
+ require 'shift_planning/connection'
3
+ require 'shift_planning/api_module'
4
+
5
+ class ShiftPlanning::Client
6
+ attr_reader :connection
7
+
8
+ def initialize(key)
9
+ @connection = ShiftPlanning::Connection.new(key)
10
+ draw_routes
11
+ end
12
+
13
+ private
14
+
15
+ def draw_routes
16
+ # API map
17
+ api_module :staff do |m|
18
+ m.get :login, [:username, :password]
19
+ m.get :logout
20
+
21
+ m.get :employees
22
+ m.create :employees
23
+
24
+ m.get :employee, [:id]
25
+ m.create :employee
26
+ m.update :employee, [:id]
27
+ m.delete :employee, [:id]
28
+
29
+ m.get :skills
30
+ m.get :skill, [:id]
31
+ m.create :skill, [:name]
32
+ m.update :skill, [:id, :name]
33
+ m.delete :skill, [:id]
34
+
35
+ m.get :customfields
36
+ m.get :customfield, [:id]
37
+ m.create :customfield, [:name, :type]
38
+ m.update :customfield, [:id]
39
+ m.delete :customfield, [:id]
40
+
41
+ m.create :ping, [:to, :message]
42
+
43
+ m.update :formatcheck, [:type]
44
+
45
+ m.get :leavetypes
46
+ m.update :leavetypes, [:id]
47
+ end
48
+
49
+ api_module :terminal do |m|
50
+ m.get :login, [:terminal_key]
51
+ m.get :clockin, [:terminal_key]
52
+ m.get :clockout, [:terminal_key]
53
+ end
54
+
55
+ api_module :location do |m|
56
+ m.get :locations
57
+
58
+ m.get :location, [:id]
59
+ m.create :location, [:name, :type]
60
+ m.update :location, [:id]
61
+ m.delete :location, [:id]
62
+ end
63
+
64
+ api_module :api do |m|
65
+ m.get :methods
66
+ m.get :config
67
+ end
68
+
69
+ api_module :timeclock do |m|
70
+ m.get :timeclocks
71
+
72
+ m.get :timeclock, [:id]
73
+ m.create :timeclock, [:start_date, :schedule, :employee, :start_time]
74
+ m.update :timeclock, [:id]
75
+ m.delete :timeclock, [:id]
76
+
77
+ m.get :clockin
78
+
79
+ m.get :preclockin
80
+ m.create :preclockin
81
+
82
+ m.get :preclockins
83
+
84
+ m.get :clockout
85
+
86
+ m.get :status
87
+
88
+ m.get :manage, [:id, :action]
89
+
90
+ m.get :screenshots
91
+
92
+ m.create :screenshot, [:filedata]
93
+
94
+ m.create :event, [:timeclock, :type]
95
+ m.update :event, [:timeclock, :type]
96
+ m.delete :event, [:timeclock, :type, :event]
97
+
98
+ m.get :timesheets
99
+
100
+ m.get :addclocktime, [:employee, :datein]
101
+
102
+ m.get :savenote, [:id]
103
+
104
+ m.get :forceclockout, [:id]
105
+
106
+ m.create :location, [:name]
107
+ m.delete :location, [:id]
108
+
109
+ m.create :terminal, [:name, :location]
110
+ m.update :terminal, [:id]
111
+ m.delete :terminal, [:id]
112
+ end
113
+
114
+ api_module :schedule do |m|
115
+ m.get :schedules
116
+
117
+ m.get :schedule, [:id]
118
+ m.create :schedule, [:name]
119
+ m.update :schedule, [:id]
120
+ m.delete :schedule, [:id]
121
+
122
+ m.get :shifts
123
+
124
+ m.get :shift, [:id]
125
+ m.create :shift, [:start_time, :end_time, :start_date, :end_date]
126
+ m.update :shift, [:id]
127
+ m.delete :shift, [:id]
128
+
129
+ m.get :shiftapprove, [:id]
130
+ m.create :shiftapprove, [:id]
131
+ m.update :shiftapprove #?
132
+ m.delete :shiftapprove, [:id]
133
+
134
+ m.get :trades
135
+
136
+ m.get :trade, [:id]
137
+ m.create :trade, [:shift, :tradewith, :reason]
138
+ m.update :trade, [:trade, :action]
139
+
140
+ m.get :tradelist, [:id]
141
+
142
+ m.create :tradeswap, [:shift, :swap, :reason]
143
+ m.update :tradeswap, [:trade, :action]
144
+
145
+ m.get :vacations
146
+
147
+ m.get :vacation, [:id]
148
+ m.create :vacation, [:start_date, :end_date]
149
+ m.update :vacation, [:id]
150
+ m.delete :vacation, [:id]
151
+
152
+ m.get :collisions, [:start_date, :end_date]
153
+
154
+ m.get :conflicts
155
+
156
+ m.get :copy, [:from_start, :from_end, :to_start, :to_end]
157
+
158
+ m.get :clear
159
+
160
+ m.get :restore
161
+
162
+ m.get :wizard, [:from_start, :from_end, :to_start, :to_end]
163
+
164
+ m.update :adjust, [:from, :to, :budge]
165
+
166
+ m.get :fill, [:shifts]
167
+
168
+ m.get :publish, [:shifts]
169
+
170
+ m.update :requests, [:id, :type, :mode]
171
+
172
+ m.create :ical, [:url, :name]
173
+ m.update :ical, [:ical_id]
174
+ m.get :ical # [:id] ?
175
+ m.delete :ical # [:ical_id] ?
176
+
177
+ m.create :ical_events, [:ical_id]
178
+ m.update :ical_events #?
179
+ m.get :ical_events
180
+ m.delete :ical_events # [:ical_event_id] ?
181
+
182
+ m.get :breakrule, [:id]
183
+ m.create :breakrule, [:id, :break, :paid]
184
+ m.delete :breakrule, [:id]
185
+
186
+ m.create :shiftrequests, [:shift]
187
+
188
+ m.get :notes, [:start_date]
189
+
190
+ m.get :note, [:id]
191
+ m.create :note, [:date, :note]
192
+ m.update :note, [:id]
193
+ m.delete :note, [:id]
194
+
195
+ m.get :count_notes, [:start_date, :end_date]
196
+
197
+ m.get :publish_note, [:id]
198
+ end
199
+ end
200
+
201
+ def api_module(name, &block)
202
+ mod = Class.new(ShiftPlanning::ApiModule)
203
+ block.call(mod)
204
+ self.class.class_eval { attr_reader name }
205
+ instance_variable_set "@#{ name }", mod.new(connection, name)
206
+ end
207
+ end
@@ -0,0 +1,45 @@
1
+ class ShiftPlanning::Connection
2
+ attr_reader :http
3
+
4
+ def initialize(key)
5
+ @key = key
6
+ @token = nil
7
+ @http = Faraday.new(url: "http://www.shiftplanning.com") do |conn|
8
+ conn.request :url_encoded
9
+
10
+ conn.response :json
11
+ conn.response :logger
12
+
13
+ conn.adapter Faraday.default_adapter
14
+ end
15
+ end
16
+
17
+ def call(method, command, params = {})
18
+ request_params = {
19
+ request: params.merge(
20
+ method: method,
21
+ module: command
22
+ ),
23
+ output: 'json'
24
+ }
25
+
26
+ response = http.post('/api/', data: JSON::generate(signed_params(request_params))).body
27
+ ShiftPlanning::ApiError.parse(response['status'])
28
+
29
+ parse_data response do |data|
30
+ @token = data['token'] if data.has_key?('token')
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def parse_data(response_data, &block)
37
+ data = response_data
38
+ block.call(data) if block_given?
39
+ data['data']
40
+ end
41
+
42
+ def signed_params(params)
43
+ params.merge(key: @key, token: @token)
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module ShiftPlanning
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "shift_planning/version"
4
+ require "shift_planning/client"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shift_planning/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shift_planning_client"
8
+ spec.version = ShiftPlanning::VERSION
9
+ spec.authors = ["Askar Zinurov"]
10
+ spec.email = ["mail@asktim.ru"]
11
+ spec.summary = %q{Client library to www.shiftplanning.com}
12
+ spec.description = %q{}
13
+ spec.homepage = "https://github.com/AskarZinurov/shift_planning"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake", "~> 10.4"
23
+ spec.add_development_dependency "rspec", "~> 3.1.7"
24
+
25
+ spec.add_runtime_dependency 'faraday', "~> 0.9"
26
+ spec.add_runtime_dependency 'faraday_middleware', "~> 0.9.1"
27
+ end
@@ -0,0 +1,29 @@
1
+ require "shift_planning"
2
+
3
+ describe ShiftPlanning::Client do
4
+ context 'staff' do
5
+ subject(:client) { described_class.new(ENV['SHIFT_PLANNING_KEY']) }
6
+
7
+ it 'should raise argument error' do
8
+ expect{ client.staff.get_login('azaza') }.to raise_error(ArgumentError)
9
+ end
10
+
11
+ it 'should raise ApiError' do
12
+ expect{ client.staff.get_login('azaza', 'lalka') }.to raise_error(ShiftPlanning::ApiError)
13
+ end
14
+
15
+ context 'logged in' do
16
+ before do
17
+ client.staff.get_login(ENV['SHIFT_PLANNING_STAFF_USERNAME'], ENV['SHIFT_PLANNING_STAFF_PASSWORD'])
18
+ end
19
+
20
+ it 'should return skills' do
21
+ client.staff.get_skills.should == ''
22
+ end
23
+
24
+ it 'can logout' do
25
+ client.staff.get_logout.should == ''
26
+ end
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shift_planning_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Askar Zinurov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.7
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday_middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.1
83
+ description: ''
84
+ email:
85
+ - mail@asktim.ru
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/shift_planning.rb
96
+ - lib/shift_planning/api_error.rb
97
+ - lib/shift_planning/api_module.rb
98
+ - lib/shift_planning/client.rb
99
+ - lib/shift_planning/connection.rb
100
+ - lib/shift_planning/version.rb
101
+ - shift_planning.gemspec
102
+ - spec/client_spec.rb
103
+ homepage: https://github.com/AskarZinurov/shift_planning
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.0
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Client library to www.shiftplanning.com
127
+ test_files:
128
+ - spec/client_spec.rb