wheniwork-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +19 -0
  3. data/Gemfile.lock +106 -0
  4. data/LICENSE +201 -0
  5. data/README.md +111 -0
  6. data/docs/DefaultApi.md +240 -0
  7. data/docs/InlineResponse200.md +8 -0
  8. data/docs/InlineResponse2001.md +10 -0
  9. data/docs/InlineResponse2002.md +8 -0
  10. data/docs/InlineResponse2003.md +8 -0
  11. data/docs/Position.md +11 -0
  12. data/docs/Shift.md +20 -0
  13. data/docs/User.md +17 -0
  14. data/git_push.sh +67 -0
  15. data/lib/wheniwork-ruby.rb +56 -0
  16. data/lib/wheniwork-ruby/api/api.rb +279 -0
  17. data/lib/wheniwork-ruby/api_client.rb +371 -0
  18. data/lib/wheniwork-ruby/api_error.rb +45 -0
  19. data/lib/wheniwork-ruby/configuration.rb +191 -0
  20. data/lib/wheniwork-ruby/models/inline_response_200.rb +195 -0
  21. data/lib/wheniwork-ruby/models/inline_response_200_1.rb +215 -0
  22. data/lib/wheniwork-ruby/models/inline_response_200_2.rb +195 -0
  23. data/lib/wheniwork-ruby/models/inline_response_200_3.rb +195 -0
  24. data/lib/wheniwork-ruby/models/position.rb +222 -0
  25. data/lib/wheniwork-ruby/models/shift.rb +303 -0
  26. data/lib/wheniwork-ruby/models/user.rb +280 -0
  27. data/lib/wheniwork-ruby/version.rb +24 -0
  28. data/spec/api/api_spec.rb +99 -0
  29. data/spec/api_client_spec.rb +260 -0
  30. data/spec/configuration_spec.rb +46 -0
  31. data/spec/models/inline_response_200_1_spec.rb +63 -0
  32. data/spec/models/inline_response_200_2_spec.rb +51 -0
  33. data/spec/models/inline_response_200_3_spec.rb +51 -0
  34. data/spec/models/inline_response_200_spec.rb +51 -0
  35. data/spec/models/position_spec.rb +69 -0
  36. data/spec/models/shift_spec.rb +123 -0
  37. data/spec/models/user_spec.rb +105 -0
  38. data/spec/spec_helper.rb +120 -0
  39. data/wheniwork-ruby.gemspec +53 -0
  40. metadata +273 -0
@@ -0,0 +1,45 @@
1
+ =begin
2
+ Wheniwork
3
+
4
+ OpenAPI spec version: v2
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and
18
+ limitations under the License.
19
+
20
+ =end
21
+
22
+ module WhenIWork
23
+ class ApiError < StandardError
24
+ attr_reader :code, :response_headers, :response_body
25
+
26
+ # Usage examples:
27
+ # ApiError.new
28
+ # ApiError.new("message")
29
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
30
+ # ApiError.new(:code => 404, :message => "Not Found")
31
+ def initialize(arg = nil)
32
+ if arg.is_a? Hash
33
+ arg.each do |k, v|
34
+ if k.to_s == 'message'
35
+ super v
36
+ else
37
+ instance_variable_set "@#{k}", v
38
+ end
39
+ end
40
+ else
41
+ super arg
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,191 @@
1
+ =begin
2
+ Wheniwork
3
+
4
+ OpenAPI spec version: v2
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and
18
+ limitations under the License.
19
+
20
+ =end
21
+
22
+ require 'uri'
23
+
24
+ module WhenIWork
25
+ class Configuration
26
+ # Defines url scheme
27
+ attr_accessor :scheme
28
+
29
+ # Defines url host
30
+ attr_accessor :host
31
+
32
+ # Defines url base path
33
+ attr_accessor :base_path
34
+
35
+ # Defines API keys used with API Key authentications.
36
+ #
37
+ # @return [Hash] key: parameter name, value: parameter value (API key)
38
+ #
39
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
40
+ # config.api_key['api_key'] = 'xxx'
41
+ attr_accessor :api_key
42
+
43
+ # Defines API key prefixes used with API Key authentications.
44
+ #
45
+ # @return [Hash] key: parameter name, value: API key prefix
46
+ #
47
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
48
+ # config.api_key_prefix['api_key'] = 'Token'
49
+ attr_accessor :api_key_prefix
50
+
51
+ # Defines the username used with HTTP basic authentication.
52
+ #
53
+ # @return [String]
54
+ attr_accessor :username
55
+
56
+ # Defines the password used with HTTP basic authentication.
57
+ #
58
+ # @return [String]
59
+ attr_accessor :password
60
+
61
+ # Defines the access token (Bearer) used with OAuth2.
62
+ attr_accessor :access_token
63
+
64
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
65
+ # details will be logged with `logger.debug` (see the `logger` attribute).
66
+ # Default to false.
67
+ #
68
+ # @return [true, false]
69
+ attr_accessor :debugging
70
+
71
+ # Defines the logger used for debugging.
72
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
73
+ #
74
+ # @return [#debug]
75
+ attr_accessor :logger
76
+
77
+ # Defines the temporary folder to store downloaded files
78
+ # (for API endpoints that have file response).
79
+ # Default to use `Tempfile`.
80
+ #
81
+ # @return [String]
82
+ attr_accessor :temp_folder_path
83
+
84
+ # The time limit for HTTP request in seconds.
85
+ # Default to 0 (never times out).
86
+ attr_accessor :timeout
87
+
88
+ ### TLS/SSL
89
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
90
+ # Default to true.
91
+ #
92
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
93
+ #
94
+ # @return [true, false]
95
+ attr_accessor :verify_ssl
96
+
97
+ # Set this to customize the certificate file to verify the peer.
98
+ #
99
+ # @return [String] the path to the certificate file
100
+ #
101
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
102
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
103
+ attr_accessor :ssl_ca_cert
104
+
105
+ # Client certificate file (for client certificate)
106
+ attr_accessor :cert_file
107
+
108
+ # Client private key file (for client certificate)
109
+ attr_accessor :key_file
110
+
111
+ attr_accessor :inject_format
112
+
113
+ attr_accessor :force_ending_format
114
+
115
+ def initialize
116
+ @scheme = 'https'
117
+ @host = 'api.wheniwork.com'
118
+ @base_path = '/2'
119
+ @api_key = {}
120
+ @api_key_prefix = {}
121
+ @timeout = 0
122
+ @verify_ssl = true
123
+ @cert_file = nil
124
+ @key_file = nil
125
+ @debugging = false
126
+ @inject_format = false
127
+ @force_ending_format = false
128
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
129
+
130
+ yield(self) if block_given?
131
+ end
132
+
133
+ # The default Configuration object.
134
+ def self.default
135
+ @@default ||= Configuration.new
136
+ end
137
+
138
+ def configure
139
+ yield(self) if block_given?
140
+ end
141
+
142
+ def scheme=(scheme)
143
+ # remove :// from scheme
144
+ @scheme = scheme.sub(/:\/\//, '')
145
+ end
146
+
147
+ def host=(host)
148
+ # remove http(s):// and anything after a slash
149
+ @host = host.sub(/https?:\/\//, '').split('/').first
150
+ end
151
+
152
+ def base_path=(base_path)
153
+ # Add leading and trailing slashes to base_path
154
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
155
+ @base_path = "" if @base_path == "/"
156
+ end
157
+
158
+ def base_url
159
+ url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
160
+ URI.encode(url)
161
+ end
162
+
163
+ # Gets API key (with prefix if set).
164
+ # @param [String] param_name the parameter name of API key auth
165
+ def api_key_with_prefix(param_name)
166
+ if @api_key_prefix[param_name]
167
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
168
+ else
169
+ @api_key[param_name]
170
+ end
171
+ end
172
+
173
+ # Gets Basic Auth token string
174
+ def basic_auth_token
175
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
176
+ end
177
+
178
+ # Returns Auth Settings hash for api client.
179
+ def auth_settings
180
+ {
181
+ 'apiKey' =>
182
+ {
183
+ type: 'api_key',
184
+ in: 'header',
185
+ key: 'W-Token',
186
+ value: api_key_with_prefix('W-Token')
187
+ },
188
+ }
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,195 @@
1
+ =begin
2
+ Wheniwork
3
+
4
+ OpenAPI spec version: v2
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and
18
+ limitations under the License.
19
+
20
+ =end
21
+
22
+ require 'date'
23
+
24
+ module WhenIWork
25
+
26
+ class InlineResponse200
27
+ attr_accessor :positions
28
+
29
+ # Attribute mapping from ruby-style variable name to JSON key.
30
+ def self.attribute_map
31
+ {
32
+ :'positions' => :'positions'
33
+ }
34
+ end
35
+
36
+ # Attribute type mapping.
37
+ def self.swagger_types
38
+ {
39
+ :'positions' => :'Array<Position>'
40
+ }
41
+ end
42
+
43
+ # Initializes the object
44
+ # @param [Hash] attributes Model attributes in the form of hash
45
+ def initialize(attributes = {})
46
+ return unless attributes.is_a?(Hash)
47
+
48
+ # convert string to symbol for hash key
49
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
50
+
51
+ if attributes.has_key?(:'positions')
52
+ if (value = attributes[:'positions']).is_a?(Array)
53
+ self.positions = value
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ # Show invalid properties with the reasons. Usually used together with valid?
60
+ # @return Array for valid properies with the reasons
61
+ def list_invalid_properties
62
+ invalid_properties = Array.new
63
+ return invalid_properties
64
+ end
65
+
66
+ # Check to see if the all the properties in the model are valid
67
+ # @return true if the model is valid
68
+ def valid?
69
+ end
70
+
71
+ # Checks equality by comparing each attribute.
72
+ # @param [Object] Object to be compared
73
+ def ==(o)
74
+ return true if self.equal?(o)
75
+ self.class == o.class &&
76
+ positions == o.positions
77
+ end
78
+
79
+ # @see the `==` method
80
+ # @param [Object] Object to be compared
81
+ def eql?(o)
82
+ self == o
83
+ end
84
+
85
+ # Calculates hash code according to all attributes.
86
+ # @return [Fixnum] Hash code
87
+ def hash
88
+ [positions].hash
89
+ end
90
+
91
+ # Builds the object from hash
92
+ # @param [Hash] attributes Model attributes in the form of hash
93
+ # @return [Object] Returns the model itself
94
+ def build_from_hash(attributes)
95
+ return nil unless attributes.is_a?(Hash)
96
+ self.class.swagger_types.each_pair do |key, type|
97
+ if type =~ /^Array<(.*)>/i
98
+ # check to ensure the input is an array given that the the attribute
99
+ # is documented as an array but the input is not
100
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
101
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
102
+ end
103
+ elsif !attributes[self.class.attribute_map[key]].nil?
104
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
105
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
106
+ end
107
+
108
+ self
109
+ end
110
+
111
+ # Deserializes the data based on type
112
+ # @param string type Data type
113
+ # @param string value Value to be deserialized
114
+ # @return [Object] Deserialized data
115
+ def _deserialize(type, value)
116
+ case type.to_sym
117
+ when :DateTime
118
+ DateTime.parse(value)
119
+ when :Date
120
+ Date.parse(value)
121
+ when :String
122
+ value.to_s
123
+ when :Integer
124
+ value.to_i
125
+ when :Float
126
+ value.to_f
127
+ when :BOOLEAN
128
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
129
+ true
130
+ else
131
+ false
132
+ end
133
+ when :Object
134
+ # generic object (usually a Hash), return directly
135
+ value
136
+ when /\AArray<(?<inner_type>.+)>\z/
137
+ inner_type = Regexp.last_match[:inner_type]
138
+ value.map { |v| _deserialize(inner_type, v) }
139
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
140
+ k_type = Regexp.last_match[:k_type]
141
+ v_type = Regexp.last_match[:v_type]
142
+ {}.tap do |hash|
143
+ value.each do |k, v|
144
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
145
+ end
146
+ end
147
+ else # model
148
+ temp_model = WhenIWork.const_get(type).new
149
+ temp_model.build_from_hash(value)
150
+ end
151
+ end
152
+
153
+ # Returns the string representation of the object
154
+ # @return [String] String presentation of the object
155
+ def to_s
156
+ to_hash.to_s
157
+ end
158
+
159
+ # to_body is an alias to to_hash (backward compatibility)
160
+ # @return [Hash] Returns the object in the form of hash
161
+ def to_body
162
+ to_hash
163
+ end
164
+
165
+ # Returns the object in the form of hash
166
+ # @return [Hash] Returns the object in the form of hash
167
+ def to_hash
168
+ hash = {}
169
+ self.class.attribute_map.each_pair do |attr, param|
170
+ value = self.send(attr)
171
+ next if value.nil?
172
+ hash[param] = _to_hash(value)
173
+ end
174
+ hash
175
+ end
176
+
177
+ # Outputs non-array value in the form of hash
178
+ # For object, use to_hash. Otherwise, just return the value
179
+ # @param [Object] value Any valid value
180
+ # @return [Hash] Returns the value in the form of hash
181
+ def _to_hash(value)
182
+ if value.is_a?(Array)
183
+ value.compact.map{ |v| _to_hash(v) }
184
+ elsif value.is_a?(Hash)
185
+ {}.tap do |hash|
186
+ value.each { |k, v| hash[k] = _to_hash(v) }
187
+ end
188
+ elsif value.respond_to? :to_hash
189
+ value.to_hash
190
+ else
191
+ value
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,215 @@
1
+ =begin
2
+ Wheniwork
3
+
4
+ OpenAPI spec version: v2
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and
18
+ limitations under the License.
19
+
20
+ =end
21
+
22
+ require 'date'
23
+
24
+ module WhenIWork
25
+
26
+ class InlineResponse2001
27
+ attr_accessor :start
28
+
29
+ attr_accessor :_end
30
+
31
+ attr_accessor :shifts
32
+
33
+ # Attribute mapping from ruby-style variable name to JSON key.
34
+ def self.attribute_map
35
+ {
36
+ :'start' => :'start',
37
+ :'_end' => :'end',
38
+ :'shifts' => :'shifts'
39
+ }
40
+ end
41
+
42
+ # Attribute type mapping.
43
+ def self.swagger_types
44
+ {
45
+ :'start' => :'DateTime',
46
+ :'_end' => :'DateTime',
47
+ :'shifts' => :'Array<Shift>'
48
+ }
49
+ end
50
+
51
+ # Initializes the object
52
+ # @param [Hash] attributes Model attributes in the form of hash
53
+ def initialize(attributes = {})
54
+ return unless attributes.is_a?(Hash)
55
+
56
+ # convert string to symbol for hash key
57
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
58
+
59
+ if attributes.has_key?(:'start')
60
+ self.start = attributes[:'start']
61
+ end
62
+
63
+ if attributes.has_key?(:'end')
64
+ self._end = attributes[:'end']
65
+ end
66
+
67
+ if attributes.has_key?(:'shifts')
68
+ if (value = attributes[:'shifts']).is_a?(Array)
69
+ self.shifts = value
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ # Show invalid properties with the reasons. Usually used together with valid?
76
+ # @return Array for valid properies with the reasons
77
+ def list_invalid_properties
78
+ invalid_properties = Array.new
79
+ return invalid_properties
80
+ end
81
+
82
+ # Check to see if the all the properties in the model are valid
83
+ # @return true if the model is valid
84
+ def valid?
85
+ end
86
+
87
+ # Checks equality by comparing each attribute.
88
+ # @param [Object] Object to be compared
89
+ def ==(o)
90
+ return true if self.equal?(o)
91
+ self.class == o.class &&
92
+ start == o.start &&
93
+ _end == o._end &&
94
+ shifts == o.shifts
95
+ end
96
+
97
+ # @see the `==` method
98
+ # @param [Object] Object to be compared
99
+ def eql?(o)
100
+ self == o
101
+ end
102
+
103
+ # Calculates hash code according to all attributes.
104
+ # @return [Fixnum] Hash code
105
+ def hash
106
+ [start, _end, shifts].hash
107
+ end
108
+
109
+ # Builds the object from hash
110
+ # @param [Hash] attributes Model attributes in the form of hash
111
+ # @return [Object] Returns the model itself
112
+ def build_from_hash(attributes)
113
+ return nil unless attributes.is_a?(Hash)
114
+ self.class.swagger_types.each_pair do |key, type|
115
+ if type =~ /^Array<(.*)>/i
116
+ # check to ensure the input is an array given that the the attribute
117
+ # is documented as an array but the input is not
118
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
119
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
120
+ end
121
+ elsif !attributes[self.class.attribute_map[key]].nil?
122
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
123
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
124
+ end
125
+
126
+ self
127
+ end
128
+
129
+ # Deserializes the data based on type
130
+ # @param string type Data type
131
+ # @param string value Value to be deserialized
132
+ # @return [Object] Deserialized data
133
+ def _deserialize(type, value)
134
+ case type.to_sym
135
+ when :DateTime
136
+ DateTime.parse(value)
137
+ when :Date
138
+ Date.parse(value)
139
+ when :String
140
+ value.to_s
141
+ when :Integer
142
+ value.to_i
143
+ when :Float
144
+ value.to_f
145
+ when :BOOLEAN
146
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
147
+ true
148
+ else
149
+ false
150
+ end
151
+ when :Object
152
+ # generic object (usually a Hash), return directly
153
+ value
154
+ when /\AArray<(?<inner_type>.+)>\z/
155
+ inner_type = Regexp.last_match[:inner_type]
156
+ value.map { |v| _deserialize(inner_type, v) }
157
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
158
+ k_type = Regexp.last_match[:k_type]
159
+ v_type = Regexp.last_match[:v_type]
160
+ {}.tap do |hash|
161
+ value.each do |k, v|
162
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
163
+ end
164
+ end
165
+ else # model
166
+ temp_model = WhenIWork.const_get(type).new
167
+ temp_model.build_from_hash(value)
168
+ end
169
+ end
170
+
171
+ # Returns the string representation of the object
172
+ # @return [String] String presentation of the object
173
+ def to_s
174
+ to_hash.to_s
175
+ end
176
+
177
+ # to_body is an alias to to_hash (backward compatibility)
178
+ # @return [Hash] Returns the object in the form of hash
179
+ def to_body
180
+ to_hash
181
+ end
182
+
183
+ # Returns the object in the form of hash
184
+ # @return [Hash] Returns the object in the form of hash
185
+ def to_hash
186
+ hash = {}
187
+ self.class.attribute_map.each_pair do |attr, param|
188
+ value = self.send(attr)
189
+ next if value.nil?
190
+ hash[param] = _to_hash(value)
191
+ end
192
+ hash
193
+ end
194
+
195
+ # Outputs non-array value in the form of hash
196
+ # For object, use to_hash. Otherwise, just return the value
197
+ # @param [Object] value Any valid value
198
+ # @return [Hash] Returns the value in the form of hash
199
+ def _to_hash(value)
200
+ if value.is_a?(Array)
201
+ value.compact.map{ |v| _to_hash(v) }
202
+ elsif value.is_a?(Hash)
203
+ {}.tap do |hash|
204
+ value.each { |k, v| hash[k] = _to_hash(v) }
205
+ end
206
+ elsif value.respond_to? :to_hash
207
+ value.to_hash
208
+ else
209
+ value
210
+ end
211
+ end
212
+
213
+ end
214
+
215
+ end