wheniwork 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -0
- data/.rspec +4 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +98 -0
- data/Rakefile +11 -0
- data/lib/wheniwork.rb +18 -0
- data/lib/wheniwork/client.rb +10 -0
- data/lib/wheniwork/client/shifts.rb +15 -0
- data/lib/wheniwork/configuration.rb +20 -0
- data/lib/wheniwork/request.rb +81 -0
- data/lib/wheniwork/version.rb +3 -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 +210 -0
data/.gitignore
ADDED
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,98 @@
|
|
1
|
+
# Wheniwork
|
2
|
+
|
3
|
+
[![Build Status](https://magnum.travis-ci.com/forward-labs/wheniwork.png?token=Z6AN21geTPF4HNYHvKwp&branch=master)](https://magnum.travis-ci.com/forward-labs/wheniwork)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/forward-labs/wheniwork.png)](https://codeclimate.com/github/forward-labs/wheniwork)
|
5
|
+
|
6
|
+
This is a thin ruby wrapper around the [WhenIWork's][wheniwork] API.
|
7
|
+
|
8
|
+
NOTE: this is a work in progress. Please check the TODO section for details
|
9
|
+
on what's missing. Contributions are welcome!
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'wheniwork'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install wheniwork
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
In order to use it, require the gem:
|
28
|
+
|
29
|
+
require 'wheniwork'
|
30
|
+
|
31
|
+
Then, add your credentials to the configuration:
|
32
|
+
|
33
|
+
WhenIWork.configure do |c|
|
34
|
+
c.username = '<YOUR USERNAME>'
|
35
|
+
c.password = '<YOUR PASSWORD>'
|
36
|
+
c.api_key = '<YOUR API KEY>'
|
37
|
+
end
|
38
|
+
|
39
|
+
Check the options section to see what configuration options you can use.
|
40
|
+
Finally, use the client:
|
41
|
+
|
42
|
+
=> client = WhenIWork::Client.new
|
43
|
+
=> client.shifts
|
44
|
+
=> => {"start"=>"Fri, 19 Jul 2013 16:56:34 +0100",
|
45
|
+
"end"=>"Mon, 22 Jul 2013 16:56:34 +0100",
|
46
|
+
"shifts"=>
|
47
|
+
[{"id"=>10876241,
|
48
|
+
"account_id"=>11111,
|
49
|
+
"user_id"=>222222,
|
50
|
+
"location_id"=>33333,
|
51
|
+
"position_id"=>44444,
|
52
|
+
...
|
53
|
+
|
54
|
+
|
55
|
+
## Caching
|
56
|
+
|
57
|
+
The gem uses active support caching to cache the requests for 1 minute. This
|
58
|
+
is configurable through the configuration block:
|
59
|
+
|
60
|
+
WhenIWork.configure do |c|
|
61
|
+
c.cache_store = Rails.cache
|
62
|
+
c.cache_enabled = true
|
63
|
+
end
|
64
|
+
|
65
|
+
If you set cache_enabled to false, nothing will be cached:
|
66
|
+
|
67
|
+
WhenIWork.configure do |c|
|
68
|
+
c.cache_enabled = false
|
69
|
+
end
|
70
|
+
|
71
|
+
## TODO
|
72
|
+
|
73
|
+
- Add missing endpoints - we currently only handle a few endpoints, would be
|
74
|
+
great to be able to cover the entire API;
|
75
|
+
- Error handling - there isn't error handling at the moment - something to
|
76
|
+
consider when issues occur;
|
77
|
+
- Test caching logic.
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
1. [Fork the repository.][fork]
|
82
|
+
2. [Create a topic branch.][branch]
|
83
|
+
3. Add specs for your unimplemented feature or bug fix.
|
84
|
+
4. Run `bundle exec rake`. If your specs pass, return to step 3.
|
85
|
+
5. Implement your feature or bug fix.
|
86
|
+
6. Run `bundle exec rake`. If your specs fail, return to step 5.
|
87
|
+
7. Add documentation for your feature or bug fix.
|
88
|
+
8. Add, commit, and push your changes.
|
89
|
+
9. [Submit a pull request.][pr]
|
90
|
+
|
91
|
+
## Copyright
|
92
|
+
Copyright (c) 2013 Forward Labs. See [LICENSE][] for details.
|
93
|
+
|
94
|
+
[license]: https://github.com/forward-labs/wheniwork/blob/master/LICENSE.txt
|
95
|
+
[fork]: http://help.github.com/fork-a-repo/
|
96
|
+
[branch]: http://learn.github.com/p/branching.html
|
97
|
+
[pr]: http://help.github.com/send-pull-requests/
|
98
|
+
[wheniwork]: http://dev.wheniwork.com/
|
data/Rakefile
ADDED
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,15 @@
|
|
1
|
+
module WhenIWork
|
2
|
+
class Client
|
3
|
+
module Shifts
|
4
|
+
|
5
|
+
def shifts(params = {}, options = {})
|
6
|
+
get 'shifts', params, options.merge(key: 'wheniwork_shifts')
|
7
|
+
end
|
8
|
+
|
9
|
+
def shift(shift_id, params = {}, options = {})
|
10
|
+
get "shifts/#{shift_id}", params, options
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
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,81 @@
|
|
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
|
+
end
|
24
|
+
|
25
|
+
def cache_key_for(uri, params)
|
26
|
+
params[:uri] = uri
|
27
|
+
::Marshal.dump(params)
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_options
|
31
|
+
{ expires_in: WhenIWork.configuration.expires_in }
|
32
|
+
end
|
33
|
+
|
34
|
+
def connection
|
35
|
+
@connection ||= Faraday.new(:url => endpoint) do |faraday|
|
36
|
+
faraday.request :url_encoded
|
37
|
+
|
38
|
+
faraday.response :json, :content_type => /\bjson$/
|
39
|
+
faraday.adapter Faraday.default_adapter
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def default_request_params
|
44
|
+
{ "W-Token" => token }
|
45
|
+
end
|
46
|
+
|
47
|
+
def endpoint
|
48
|
+
WhenIWork.configuration.endpoint
|
49
|
+
end
|
50
|
+
|
51
|
+
def token
|
52
|
+
if cache_enabled
|
53
|
+
cache_store.fetch('wheniwork_token', default_options) do
|
54
|
+
login['token']
|
55
|
+
end
|
56
|
+
else
|
57
|
+
login['token']
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def auth_params
|
62
|
+
{
|
63
|
+
username: WhenIWork.configuration.username,
|
64
|
+
password: WhenIWork.configuration.password,
|
65
|
+
key: WhenIWork.configuration.api_key
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def login
|
70
|
+
connection.post('login', auth_params.to_json).body
|
71
|
+
end
|
72
|
+
|
73
|
+
def cache_store
|
74
|
+
WhenIWork.configuration.cache_store
|
75
|
+
end
|
76
|
+
|
77
|
+
def cache_enabled
|
78
|
+
WhenIWork.configuration.cache_enabled
|
79
|
+
end
|
80
|
+
end
|
81
|
+
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"
|
8
|
+
spec.version = Wheniwork::VERSION
|
9
|
+
spec.authors = ["Carlos Vilhena"]
|
10
|
+
spec.email = ["carlosvilhena@gmail.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,210 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wheniwork
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Carlos Vilhena
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.8'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.8'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday_middleware
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.9'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.9'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activesupport
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.2'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.14'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.14'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: webmock
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.13'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.13'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: bundler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.3'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.3'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rake
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
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
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: pry
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
description: Wrapper for the WhenIWork's API
|
143
|
+
email:
|
144
|
+
- carlosvilhena@gmail.com
|
145
|
+
executables: []
|
146
|
+
extensions: []
|
147
|
+
extra_rdoc_files: []
|
148
|
+
files:
|
149
|
+
- .gitignore
|
150
|
+
- .rspec
|
151
|
+
- .travis.yml
|
152
|
+
- Gemfile
|
153
|
+
- LICENSE.txt
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- lib/wheniwork.rb
|
157
|
+
- lib/wheniwork/client.rb
|
158
|
+
- lib/wheniwork/client/shifts.rb
|
159
|
+
- lib/wheniwork/configuration.rb
|
160
|
+
- lib/wheniwork/request.rb
|
161
|
+
- lib/wheniwork/version.rb
|
162
|
+
- spec/fixtures/empty_shifts.json
|
163
|
+
- spec/fixtures/shift_976.json
|
164
|
+
- spec/fixtures/shift_unknown.json
|
165
|
+
- spec/fixtures/shifts.json
|
166
|
+
- spec/spec_helper.rb
|
167
|
+
- spec/support/stub_request.rb
|
168
|
+
- spec/wheniwork/client/shifts_spec.rb
|
169
|
+
- spec/wheniwork/configuration_spec.rb
|
170
|
+
- wheniwork.gemspec
|
171
|
+
homepage: ''
|
172
|
+
licenses:
|
173
|
+
- MIT
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
none: false
|
180
|
+
requirements:
|
181
|
+
- - ! '>='
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
segments:
|
185
|
+
- 0
|
186
|
+
hash: -1138606947502030162
|
187
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
|
+
none: false
|
189
|
+
requirements:
|
190
|
+
- - ! '>='
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
segments:
|
194
|
+
- 0
|
195
|
+
hash: -1138606947502030162
|
196
|
+
requirements: []
|
197
|
+
rubyforge_project:
|
198
|
+
rubygems_version: 1.8.23
|
199
|
+
signing_key:
|
200
|
+
specification_version: 3
|
201
|
+
summary: Wrapper for the WhenIWork's API
|
202
|
+
test_files:
|
203
|
+
- spec/fixtures/empty_shifts.json
|
204
|
+
- spec/fixtures/shift_976.json
|
205
|
+
- spec/fixtures/shift_unknown.json
|
206
|
+
- spec/fixtures/shifts.json
|
207
|
+
- spec/spec_helper.rb
|
208
|
+
- spec/support/stub_request.rb
|
209
|
+
- spec/wheniwork/client/shifts_spec.rb
|
210
|
+
- spec/wheniwork/configuration_spec.rb
|