wheniwork_ext 0.0.6
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 +7 -0
- data/.gitignore +16 -0
- data/.project +17 -0
- data/.rspec +4 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +99 -0
- data/Rakefile +11 -0
- data/lib/wheniwork/client/availabilities.rb +15 -0
- data/lib/wheniwork/client/locations.rb +14 -0
- data/lib/wheniwork/client/positions.rb +14 -0
- data/lib/wheniwork/client/shifts.rb +20 -0
- data/lib/wheniwork/client/users.rb +14 -0
- data/lib/wheniwork/client.rb +19 -0
- data/lib/wheniwork/configuration.rb +20 -0
- data/lib/wheniwork/request.rb +82 -0
- data/lib/wheniwork/version.rb +3 -0
- data/lib/wheniwork.rb +18 -0
- data/spec/fixtures/empty_shifts.json +1 -0
- data/spec/fixtures/shift_976.json +25 -0
- data/spec/fixtures/shift_unknown.json +1 -0
- data/spec/fixtures/shifts.json +185 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/stub_request.rb +19 -0
- data/spec/wheniwork/client/shifts_spec.rb +73 -0
- data/spec/wheniwork/configuration_spec.rb +17 -0
- data/wheniwork.gemspec +30 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 40ec1f860d6391f84350d8309872645ba81c482e
|
4
|
+
data.tar.gz: 90e4512912e1f50ddbdd0816ed37ffc489cb303d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c256b05829ed66c981d69e6ca46c4a6bad17ba82d5bc0c73ef3c27341b2aaee73f1e31823b22b8c701a5919c32be021cc3c225937e04de7eebdbdd3ae016137
|
7
|
+
data.tar.gz: 5461c198110a0300628417a9f1f69a7f323932e944dba3a781f9b08d49dcf81865c7a4633ed461c0d00bc5f7ccf47810358ba5fa9dd6f9fca21bcfb7f111b528
|
data/.gitignore
ADDED
data/.project
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>wheniwork-dev</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>com.aptana.ide.core.unifiedBuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>com.aptana.ruby.core.rubynature</nature>
|
16
|
+
</natures>
|
17
|
+
</projectDescription>
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Forward Labs
|
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,99 @@
|
|
1
|
+
# Wheniwork
|
2
|
+
|
3
|
+
[](https://travis-ci.org/forward-labs/wheniwork)
|
4
|
+
[](https://codeclimate.com/github/forward-labs/wheniwork)
|
5
|
+
[](http://badge.fury.io/rb/wheniwork)
|
6
|
+
|
7
|
+
This is a thin ruby wrapper around the [WhenIWork's][wheniwork] API.
|
8
|
+
|
9
|
+
NOTE: this is a work in progress. Please check the TODO section for details
|
10
|
+
on what's missing. Contributions are welcome!
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'wheniwork'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install wheniwork
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
In order to use it, require the gem:
|
29
|
+
|
30
|
+
require 'wheniwork'
|
31
|
+
|
32
|
+
Then, add your credentials to the configuration:
|
33
|
+
|
34
|
+
WhenIWork.configure do |c|
|
35
|
+
c.username = '<YOUR USERNAME>'
|
36
|
+
c.password = '<YOUR PASSWORD>'
|
37
|
+
c.api_key = '<YOUR API KEY>'
|
38
|
+
end
|
39
|
+
|
40
|
+
Check the options section to see what configuration options you can use.
|
41
|
+
Finally, use the client:
|
42
|
+
|
43
|
+
=> client = WhenIWork::Client.new
|
44
|
+
=> client.shifts
|
45
|
+
=> => {"start"=>"Fri, 19 Jul 2013 16:56:34 +0100",
|
46
|
+
"end"=>"Mon, 22 Jul 2013 16:56:34 +0100",
|
47
|
+
"shifts"=>
|
48
|
+
[{"id"=>10876241,
|
49
|
+
"account_id"=>11111,
|
50
|
+
"user_id"=>222222,
|
51
|
+
"location_id"=>33333,
|
52
|
+
"position_id"=>44444,
|
53
|
+
...
|
54
|
+
|
55
|
+
|
56
|
+
## Caching
|
57
|
+
|
58
|
+
The gem uses active support caching to cache the requests for 1 minute. This
|
59
|
+
is configurable through the configuration block:
|
60
|
+
|
61
|
+
WhenIWork.configure do |c|
|
62
|
+
c.cache_store = Rails.cache
|
63
|
+
c.cache_enabled = true
|
64
|
+
end
|
65
|
+
|
66
|
+
If you set cache_enabled to false, nothing will be cached:
|
67
|
+
|
68
|
+
WhenIWork.configure do |c|
|
69
|
+
c.cache_enabled = false
|
70
|
+
end
|
71
|
+
|
72
|
+
## TODO
|
73
|
+
|
74
|
+
- Add missing endpoints - we currently only handle a few endpoints, would be
|
75
|
+
great to be able to cover the entire API;
|
76
|
+
- Error handling - there isn't error handling at the moment - something to
|
77
|
+
consider when issues occur;
|
78
|
+
- Test caching logic.
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
1. [Fork the repository.][fork]
|
83
|
+
2. [Create a topic branch.][branch]
|
84
|
+
3. Add specs for your unimplemented feature or bug fix.
|
85
|
+
4. Run `bundle exec rake`. If your specs pass, return to step 3.
|
86
|
+
5. Implement your feature or bug fix.
|
87
|
+
6. Run `bundle exec rake`. If your specs fail, return to step 5.
|
88
|
+
7. Add documentation for your feature or bug fix.
|
89
|
+
8. Add, commit, and push your changes.
|
90
|
+
9. [Submit a pull request.][pr]
|
91
|
+
|
92
|
+
## Copyright
|
93
|
+
Copyright (c) 2013 Forward Labs. See [LICENSE][] for details.
|
94
|
+
|
95
|
+
[license]: https://github.com/forward-labs/wheniwork/blob/master/LICENSE.txt
|
96
|
+
[fork]: http://help.github.com/fork-a-repo/
|
97
|
+
[branch]: http://learn.github.com/p/branching.html
|
98
|
+
[pr]: http://help.github.com/send-pull-requests/
|
99
|
+
[wheniwork]: http://dev.wheniwork.com/
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module WhenIWork
|
2
|
+
class Client
|
3
|
+
module Availabilities
|
4
|
+
|
5
|
+
def availabilities(user_id, params = {}, options = {})
|
6
|
+
get "availabilities?user_id=#{user_id}", params, options
|
7
|
+
end
|
8
|
+
|
9
|
+
def availabilities_by_criteria(user_id_array,start_datetime, end_datetime, params = {}, options = {})
|
10
|
+
get "availabilities/items?user_id=#{user_id_array}&start=#{start_datetime}&end=#{end_datetime}", params, options
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module WhenIWork
|
2
|
+
class Client
|
3
|
+
module Locations
|
4
|
+
|
5
|
+
def locations(params = {}, options = {})
|
6
|
+
get 'locations', params, options.merge(key: 'wheniwork_locations')
|
7
|
+
end
|
8
|
+
def location(location_id, params = {}, options = {})
|
9
|
+
get "locations/#{location_id}", params, options
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module WhenIWork
|
2
|
+
class Client
|
3
|
+
module Positions
|
4
|
+
|
5
|
+
def positions(params = {}, options = {})
|
6
|
+
get 'positions', params, options.merge(key: 'wheniwork_positions')
|
7
|
+
end
|
8
|
+
def position(position_id, params = {}, options = {})
|
9
|
+
get "positions/#{position_id}", params, options
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module WhenIWork
|
2
|
+
class Client
|
3
|
+
module Shifts
|
4
|
+
def positions(params = {}, options = {})
|
5
|
+
get 'positions', params, options.merge(key: 'wheniwork_positions')
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def shifts(params = {}, options = {})
|
10
|
+
get 'shifts', params, options.merge(key: 'wheniwork_shifts')
|
11
|
+
end
|
12
|
+
|
13
|
+
def shift(shift_id, params = {}, options = {})
|
14
|
+
get "shifts/#{shift_id}", params, options
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module WhenIWork
|
2
|
+
class Client
|
3
|
+
module Users
|
4
|
+
|
5
|
+
def users(params = {}, options = {})
|
6
|
+
get 'users', params, options.merge(key: 'wheniwork_users')
|
7
|
+
end
|
8
|
+
def user(user_id, params = {}, options = {})
|
9
|
+
get "users/#{user_id}", params, options
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'wheniwork/request'
|
2
|
+
require 'wheniwork/client/users'
|
3
|
+
require 'wheniwork/client/shifts'
|
4
|
+
require 'wheniwork/client/positions'
|
5
|
+
require 'wheniwork/client/locations'
|
6
|
+
require 'wheniwork/client/availabilities'
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
module WhenIWork
|
11
|
+
class Client
|
12
|
+
include WhenIWork::Request
|
13
|
+
include WhenIWork::Client::Users
|
14
|
+
include WhenIWork::Client::Shifts
|
15
|
+
include WhenIWork::Client::Positions
|
16
|
+
include WhenIWork::Client::Locations
|
17
|
+
include WhenIWork::Client::Availabilities
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module WhenIWork
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :endpoint, :username, :password, :expires_in,
|
4
|
+
:api_key, :api_version, :protocol, :cache_store, :cache_enabled
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
setup_base
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup_base
|
11
|
+
self.api_version = '2'
|
12
|
+
self.protocol = 'https'
|
13
|
+
self.cache_enabled = true
|
14
|
+
self.cache_store = ActiveSupport::Cache::MemoryStore.new
|
15
|
+
self.endpoint = "#{protocol}://api.wheniwork.com/#{api_version}/"
|
16
|
+
self.expires_in = 60
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module WhenIWork
|
2
|
+
module Request
|
3
|
+
|
4
|
+
def get(path, params={}, options={})
|
5
|
+
request :get, path, default_request_params.merge(params), options
|
6
|
+
end
|
7
|
+
|
8
|
+
def post(path, params={}, options={})
|
9
|
+
request :post, path, default_request_params.merge(params), options
|
10
|
+
end
|
11
|
+
|
12
|
+
def request(method, path, params, cache_options)
|
13
|
+
if cache_enabled
|
14
|
+
key = cache_options.delete(:key) || cache_key_for(path, params)
|
15
|
+
options = default_options.merge(cache_options)
|
16
|
+
|
17
|
+
cache_store.fetch(key, options) do
|
18
|
+
connection.send(method, path, params).body
|
19
|
+
end
|
20
|
+
else
|
21
|
+
connection.send(method, path, params).body
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def cache_key_for(uri, params)
|
27
|
+
params[:uri] = uri
|
28
|
+
::Marshal.dump(params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def default_options
|
32
|
+
{ expires_in: WhenIWork.configuration.expires_in }
|
33
|
+
end
|
34
|
+
|
35
|
+
def connection
|
36
|
+
@connection ||= Faraday.new(:url => endpoint) do |faraday|
|
37
|
+
faraday.request :url_encoded
|
38
|
+
|
39
|
+
faraday.response :json, :content_type => /\bjson$/
|
40
|
+
faraday.adapter Faraday.default_adapter
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def default_request_params
|
45
|
+
{ "W-Token" => token }
|
46
|
+
end
|
47
|
+
|
48
|
+
def endpoint
|
49
|
+
WhenIWork.configuration.endpoint
|
50
|
+
end
|
51
|
+
|
52
|
+
def token
|
53
|
+
if cache_enabled
|
54
|
+
cache_store.fetch('wheniwork_token', default_options) do
|
55
|
+
login['token']
|
56
|
+
end
|
57
|
+
else
|
58
|
+
login['token']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def auth_params
|
63
|
+
{
|
64
|
+
username: WhenIWork.configuration.username,
|
65
|
+
password: WhenIWork.configuration.password,
|
66
|
+
key: WhenIWork.configuration.api_key
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def login
|
71
|
+
connection.post('login', auth_params.to_json).body
|
72
|
+
end
|
73
|
+
|
74
|
+
def cache_store
|
75
|
+
WhenIWork.configuration.cache_store
|
76
|
+
end
|
77
|
+
|
78
|
+
def cache_enabled
|
79
|
+
WhenIWork.configuration.cache_enabled
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/wheniwork.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'faraday'
|
3
|
+
require 'active_support'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
|
6
|
+
require 'wheniwork/version'
|
7
|
+
require 'wheniwork/configuration'
|
8
|
+
require 'wheniwork/client'
|
9
|
+
|
10
|
+
module WhenIWork
|
11
|
+
def self.configuration
|
12
|
+
@configuration ||= WhenIWork::Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configure
|
16
|
+
yield(configuration) if block_given?
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"start":"Wed, 01 Jan 2014 00:00:00 +0000","end":"Sat, 04 Jan 2014 00:00:00 +0000","shifts":[]}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"shift":{
|
3
|
+
"id":976,
|
4
|
+
"account_id":3,
|
5
|
+
"user_id":135,
|
6
|
+
"location_id":137,
|
7
|
+
"position_id":0,
|
8
|
+
"site_id":0,
|
9
|
+
"start_time":"Fri, 04 May 2012 12:00:00 -0500",
|
10
|
+
"end_time":"Sat, 05 May 2012 09:00:00 -0500",
|
11
|
+
"break_time":0,
|
12
|
+
"color":"a6d98d",
|
13
|
+
"notes":"",
|
14
|
+
"alerted":false,
|
15
|
+
"linked_users":null,
|
16
|
+
"shiftchain_key":"",
|
17
|
+
"published":true,
|
18
|
+
"published_date":"Tue, 24 Apr 2012 21:36:56 -0500",
|
19
|
+
"notified_at":"0000-00-00 00:00:00",
|
20
|
+
"created_at":"Tue, 24 Apr 2012 16:36:42 -0500",
|
21
|
+
"updated_at":"Tue, 24 Apr 2012 16:36:56 -0500",
|
22
|
+
"is_open":false,
|
23
|
+
"block_id":0
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"error":"No shift found","code":4005}
|
@@ -0,0 +1,185 @@
|
|
1
|
+
{
|
2
|
+
"start":"Mon, 30 Apr 2012 00:00:00 -0500",
|
3
|
+
"end":"Fri, 04 May 2012 23:00:00 -0500",
|
4
|
+
"shifts":[
|
5
|
+
{
|
6
|
+
"id":973,
|
7
|
+
"account_id":3,
|
8
|
+
"user_id":135,
|
9
|
+
"location_id":137,
|
10
|
+
"position_id":0,
|
11
|
+
"site_id":0,
|
12
|
+
"start_time":"Tue, 01 May 2012 04:00:00 -0500",
|
13
|
+
"end_time":"Tue, 01 May 2012 11:00:00 -0500",
|
14
|
+
"break_time":0,
|
15
|
+
"color":"11a68d",
|
16
|
+
"notes":"",
|
17
|
+
"alerted":false,
|
18
|
+
"linked_users":null,
|
19
|
+
"shiftchain_key":"",
|
20
|
+
"published":true,
|
21
|
+
"published_date":"Wed, 25 Apr 2012 11:02:47 -0500",
|
22
|
+
"notified_at":"0000-00-00 00:00:00",
|
23
|
+
"created_at":"Tue, 24 Apr 2012 16:36:36 -0500",
|
24
|
+
"updated_at":"Wed, 25 Apr 2012 11:02:47 -0500",
|
25
|
+
"is_open":false,
|
26
|
+
"block_id":0
|
27
|
+
},
|
28
|
+
{
|
29
|
+
"id":974,
|
30
|
+
"account_id":3,
|
31
|
+
"user_id":135,
|
32
|
+
"location_id":137,
|
33
|
+
"position_id":0,
|
34
|
+
"site_id":0,
|
35
|
+
"start_time":"Wed, 02 May 2012 07:00:00 -0500",
|
36
|
+
"end_time":"Thu, 03 May 2012 04:00:00 -0500",
|
37
|
+
"break_time":0,
|
38
|
+
"color":"a4cc54",
|
39
|
+
"notes":"",
|
40
|
+
"alerted":false,
|
41
|
+
"linked_users":null,
|
42
|
+
"shiftchain_key":"",
|
43
|
+
"published":true,
|
44
|
+
"published_date":"Wed, 25 Apr 2012 11:02:47 -0500",
|
45
|
+
"notified_at":"0000-00-00 00:00:00",
|
46
|
+
"created_at":"Tue, 24 Apr 2012 16:36:38 -0500",
|
47
|
+
"updated_at":"Wed, 25 Apr 2012 11:02:47 -0500",
|
48
|
+
"is_open":false,
|
49
|
+
"block_id":0
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"id":975,
|
53
|
+
"account_id":3,
|
54
|
+
"user_id":135,
|
55
|
+
"location_id":137,
|
56
|
+
"position_id":0,
|
57
|
+
"site_id":0,
|
58
|
+
"start_time":"Thu, 03 May 2012 20:00:00 -0500",
|
59
|
+
"end_time":"Fri, 04 May 2012 02:00:00 -0500",
|
60
|
+
"break_time":0,
|
61
|
+
"color":"7411a6",
|
62
|
+
"notes":"",
|
63
|
+
"alerted":false,
|
64
|
+
"linked_users":null,
|
65
|
+
"shiftchain_key":"",
|
66
|
+
"published":true,
|
67
|
+
"published_date":"Wed, 25 Apr 2012 11:02:47 -0500",
|
68
|
+
"notified_at":"0000-00-00 00:00:00",
|
69
|
+
"created_at":"Tue, 24 Apr 2012 16:36:40 -0500",
|
70
|
+
"updated_at":"Wed, 25 Apr 2012 11:02:47 -0500",
|
71
|
+
"is_open":false,
|
72
|
+
"block_id":0
|
73
|
+
},
|
74
|
+
{
|
75
|
+
"id":976,
|
76
|
+
"account_id":3,
|
77
|
+
"user_id":135,
|
78
|
+
"location_id":137,
|
79
|
+
"position_id":0,
|
80
|
+
"site_id":0,
|
81
|
+
"start_time":"Fri, 04 May 2012 07:00:00 -0500",
|
82
|
+
"end_time":"Sat, 05 May 2012 04:00:00 -0500",
|
83
|
+
"break_time":0,
|
84
|
+
"color":"a6d98d",
|
85
|
+
"notes":"",
|
86
|
+
"alerted":false,
|
87
|
+
"linked_users":null,
|
88
|
+
"shiftchain_key":"",
|
89
|
+
"published":true,
|
90
|
+
"published_date":"Wed, 25 Apr 2012 11:02:47 -0500",
|
91
|
+
"notified_at":"0000-00-00 00:00:00",
|
92
|
+
"created_at":"Tue, 24 Apr 2012 16:36:42 -0500",
|
93
|
+
"updated_at":"Wed, 25 Apr 2012 11:02:47 -0500",
|
94
|
+
"is_open":false,
|
95
|
+
"block_id":0
|
96
|
+
}
|
97
|
+
],
|
98
|
+
"users":[
|
99
|
+
{
|
100
|
+
"id":135,
|
101
|
+
"account_id":3,
|
102
|
+
"timezone_id":0,
|
103
|
+
"country_id":233,
|
104
|
+
"role":1,
|
105
|
+
"email":"jcronk@thisclicks.com",
|
106
|
+
"first_name":"Jeff",
|
107
|
+
"last_name":"Cronk",
|
108
|
+
"phone_number":"+17152734444",
|
109
|
+
"phone_email":"",
|
110
|
+
"phone_prefix":"",
|
111
|
+
"password":true,
|
112
|
+
"activated":true,
|
113
|
+
"is_hidden":false,
|
114
|
+
"uuid":"0b442d557e14e86ed15b8f037ee53cb951015aff",
|
115
|
+
"notes":"",
|
116
|
+
"affiliate":0,
|
117
|
+
"is_private":true,
|
118
|
+
"infotips":"",
|
119
|
+
"hours_preferred":0,
|
120
|
+
"hours_max":25,
|
121
|
+
"hourly_rate":11,
|
122
|
+
"alert_settings":{
|
123
|
+
"timeoff":{
|
124
|
+
"sms":true,
|
125
|
+
"email":false
|
126
|
+
},
|
127
|
+
"swaps":{
|
128
|
+
"sms":false,
|
129
|
+
"email":true
|
130
|
+
},
|
131
|
+
"schedule":{
|
132
|
+
"sms":false,
|
133
|
+
"email":true
|
134
|
+
},
|
135
|
+
"reminders":{
|
136
|
+
"sms":false,
|
137
|
+
"email":true
|
138
|
+
},
|
139
|
+
"availability":{
|
140
|
+
"sms":false,
|
141
|
+
"email":true
|
142
|
+
},
|
143
|
+
"new_employee":{
|
144
|
+
"sms":false,
|
145
|
+
"email":true
|
146
|
+
}
|
147
|
+
},
|
148
|
+
"reminder_time":8,
|
149
|
+
"sleep_start":"21:00:00",
|
150
|
+
"sleep_end":"09:00:00",
|
151
|
+
"last_login":"Wed, 25 Apr 2012 03:58:56 -0500",
|
152
|
+
"notified_at":"Tue, 17 Apr 2012 16:47:25 -0500",
|
153
|
+
"created_at":"Wed, 21 Mar 2012 09:50:25 -0500",
|
154
|
+
"updated_at":"Wed, 25 Apr 2012 10:59:27 -0500",
|
155
|
+
"avatar":{
|
156
|
+
"url":"http://www.gravatar.com/avatar/868a17d2635f6795c80103052f542628.jpg?s=%s&d=identicon&r=pg",
|
157
|
+
"size":"%s"
|
158
|
+
},
|
159
|
+
"positions":[
|
160
|
+
30
|
161
|
+
],
|
162
|
+
"locations":[
|
163
|
+
136,
|
164
|
+
137
|
165
|
+
]
|
166
|
+
}
|
167
|
+
],
|
168
|
+
"locations":[
|
169
|
+
{
|
170
|
+
"id":137,
|
171
|
+
"account_id":3,
|
172
|
+
"is_default":0,
|
173
|
+
"name":"Uptown",
|
174
|
+
"sort":0,
|
175
|
+
"max_hours":80,
|
176
|
+
"address":"4321 Your street, Your Town, MN 12345",
|
177
|
+
"coordinates":[
|
178
|
+
"45.8977016",
|
179
|
+
"-68.0365217"
|
180
|
+
],
|
181
|
+
"created_at":"Tue, 24 Apr 2012 15:09:00 -0500",
|
182
|
+
"updated_at":"Tue, 24 Apr 2012 15:09:00 -0500"
|
183
|
+
}
|
184
|
+
]
|
185
|
+
}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
|
3
|
+
module StubRequest
|
4
|
+
def stub_get(path)
|
5
|
+
stub_request(:get, url_for(path))
|
6
|
+
end
|
7
|
+
|
8
|
+
def url_for(path)
|
9
|
+
"#{WhenIWork.configuration.endpoint}#{path}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def fixture_path
|
13
|
+
File.expand_path("../../fixtures", __FILE__)
|
14
|
+
end
|
15
|
+
|
16
|
+
def fixture(file)
|
17
|
+
JSON.load(File.new(fixture_path + '/' + file))
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WhenIWork::Client::Shifts do
|
4
|
+
subject(:client) do
|
5
|
+
WhenIWork.configuration.cache_enabled = false
|
6
|
+
WhenIWork::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
before do
|
10
|
+
client.stub(:token).and_return('abc123')
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#shift' do
|
14
|
+
context 'for an existing shift' do
|
15
|
+
before { stub_get('shifts/976?W-Token=abc123').to_return(
|
16
|
+
body: fixture('shift_976.json')) }
|
17
|
+
|
18
|
+
it 'returns the expected shift' do
|
19
|
+
expect(client.shift(976)['shift']['id']).to eq(976)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'for an unknown shift' do
|
24
|
+
before { stub_get('shifts/-1?W-Token=abc123').to_return(
|
25
|
+
body: fixture('shift_unknown.json')) }
|
26
|
+
|
27
|
+
it 'does not return a shift' do
|
28
|
+
expect(client.shift(-1)['shift']).to be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns an error message' do
|
32
|
+
expect(client.shift(-1)['error']).to eq('No shift found')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns an error code' do
|
36
|
+
expect(client.shift(-1)['code']).to eq(4005)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#shifts' do
|
42
|
+
context 'with available shifts' do
|
43
|
+
before { stub_get('shifts?W-Token=abc123').to_return(
|
44
|
+
body: fixture('shifts.json')) }
|
45
|
+
|
46
|
+
it 'returns a hash of results' do
|
47
|
+
expect(client.shifts.keys).to eq(["start", "end", "shifts",
|
48
|
+
"users", "locations"])
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'contains one user' do
|
52
|
+
expect(client.shifts['users'].count).to eq(1)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'contains four shifts' do
|
56
|
+
expect(client.shifts['shifts'].count).to eq(4)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'without any shifts' do
|
61
|
+
before { stub_get('shifts?W-Token=abc123').to_return(
|
62
|
+
body: fixture('empty_shifts.json')) }
|
63
|
+
|
64
|
+
it 'returns empty shifts' do
|
65
|
+
expect(client.shifts['shifts']).to be_empty
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns no users' do
|
69
|
+
expect(client.shifts['users']).to be_nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WhenIWork::Configuration do
|
4
|
+
describe '#endpoint' do
|
5
|
+
it 'sets the correct endpoint' do
|
6
|
+
expect(subject.endpoint).to eq('https://api.wheniwork.com/2/')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'sets the default expiry time' do
|
10
|
+
expect(subject.expires_in).to eq(60)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'enables cache by default' do
|
14
|
+
expect(subject.cache_enabled).to be_true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/wheniwork.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wheniwork/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wheniwork_ext"
|
8
|
+
spec.version = Wheniwork::VERSION
|
9
|
+
spec.authors = ["Imran Haider"]
|
10
|
+
spec.email = ["haider_6017@hotmail.com"]
|
11
|
+
spec.description = %q{Wrapper for the WhenIWork's API}
|
12
|
+
spec.summary = %q{Wrapper for the WhenIWork's API}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_runtime_dependency 'faraday', '~> 0.8'
|
22
|
+
spec.add_runtime_dependency 'faraday_middleware', '~> 0.9'
|
23
|
+
spec.add_runtime_dependency 'activesupport', '~> 3.2'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'rspec', '~> 2.14'
|
26
|
+
spec.add_development_dependency 'webmock', '~> 1.13'
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
28
|
+
spec.add_development_dependency 'rake'
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wheniwork_ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Imran Haider
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.13'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.13'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Wrapper for the WhenIWork's API
|
126
|
+
email:
|
127
|
+
- haider_6017@hotmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- .gitignore
|
133
|
+
- .project
|
134
|
+
- .rspec
|
135
|
+
- .travis.yml
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- lib/wheniwork.rb
|
141
|
+
- lib/wheniwork/client.rb
|
142
|
+
- lib/wheniwork/client/availabilities.rb
|
143
|
+
- lib/wheniwork/client/locations.rb
|
144
|
+
- lib/wheniwork/client/positions.rb
|
145
|
+
- lib/wheniwork/client/shifts.rb
|
146
|
+
- lib/wheniwork/client/users.rb
|
147
|
+
- lib/wheniwork/configuration.rb
|
148
|
+
- lib/wheniwork/request.rb
|
149
|
+
- lib/wheniwork/version.rb
|
150
|
+
- spec/fixtures/empty_shifts.json
|
151
|
+
- spec/fixtures/shift_976.json
|
152
|
+
- spec/fixtures/shift_unknown.json
|
153
|
+
- spec/fixtures/shifts.json
|
154
|
+
- spec/spec_helper.rb
|
155
|
+
- spec/support/stub_request.rb
|
156
|
+
- spec/wheniwork/client/shifts_spec.rb
|
157
|
+
- spec/wheniwork/configuration_spec.rb
|
158
|
+
- wheniwork.gemspec
|
159
|
+
homepage: ''
|
160
|
+
licenses:
|
161
|
+
- MIT
|
162
|
+
metadata: {}
|
163
|
+
post_install_message:
|
164
|
+
rdoc_options: []
|
165
|
+
require_paths:
|
166
|
+
- lib
|
167
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - '>='
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
173
|
+
requirements:
|
174
|
+
- - '>='
|
175
|
+
- !ruby/object:Gem::Version
|
176
|
+
version: '0'
|
177
|
+
requirements: []
|
178
|
+
rubyforge_project:
|
179
|
+
rubygems_version: 2.2.2
|
180
|
+
signing_key:
|
181
|
+
specification_version: 4
|
182
|
+
summary: Wrapper for the WhenIWork's API
|
183
|
+
test_files:
|
184
|
+
- spec/fixtures/empty_shifts.json
|
185
|
+
- spec/fixtures/shift_976.json
|
186
|
+
- spec/fixtures/shift_unknown.json
|
187
|
+
- spec/fixtures/shifts.json
|
188
|
+
- spec/spec_helper.rb
|
189
|
+
- spec/support/stub_request.rb
|
190
|
+
- spec/wheniwork/client/shifts_spec.rb
|
191
|
+
- spec/wheniwork/configuration_spec.rb
|