when-i-work 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/when-i-work.rb +10 -4
- data/lib/when-i-work/authentication.rb +1 -2
- data/lib/when-i-work/resource.rb +2 -2
- data/lib/when-i-work/shift.rb +1 -1
- data/spec/resources/shift_spec.rb +2 -6
- data/spec/spec_helper.rb +4 -0
- data/when-i-work.gemspec +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c03cba8607c9af712614d7166cf0afea2e94233c
|
4
|
+
data.tar.gz: c04241572ebe7b4ecb8ebc8091f1a4f598ffb1e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60cd6c7c53eae30036bd8c17e8191ca2f07bb115974232cadd2ace783d7fd6219d1820b058708e558d9d66db6c8b54977e8ebb7827b5ab87aa6e1a8ced5605c0
|
7
|
+
data.tar.gz: 52f211b2e53dc97e5c888f3a7919613cbec095f060a91a3faae8b8f687b44da4668e86673cc6c8b918bde8dc702b85ad3b5b75bbff00c3da12b749a3ecb65e13
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
data/lib/when-i-work.rb
CHANGED
@@ -9,23 +9,29 @@ require_relative 'when-i-work/shift'
|
|
9
9
|
|
10
10
|
module WhenIWork
|
11
11
|
class << self
|
12
|
-
attr_accessor :token
|
12
|
+
attr_accessor :username, :password, :api_key, :token
|
13
13
|
|
14
14
|
def api_url
|
15
15
|
"https://api.wheniwork.com/2/"
|
16
16
|
end
|
17
17
|
|
18
18
|
def configure(username, password, api_key)
|
19
|
-
|
19
|
+
self.username = username
|
20
|
+
self.password = password
|
21
|
+
self.api_key = api_key
|
20
22
|
end
|
21
23
|
|
22
|
-
def client
|
24
|
+
def client(options = {})
|
25
|
+
unless options[:skip_authentication]
|
26
|
+
self.token ||= Authentication.login(username, password, api_key)
|
27
|
+
end
|
28
|
+
|
23
29
|
Faraday.new(url: api_url) do |faraday|
|
24
30
|
#faraday.response :detailed_logger
|
25
31
|
faraday.request :json
|
26
32
|
faraday.response :json, :content_type => /\bjson$/
|
27
33
|
faraday.adapter Faraday.default_adapter
|
28
|
-
faraday.headers = { 'W-Token' =>
|
34
|
+
faraday.headers = { 'W-Token' => self.token } if self.token
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
@@ -4,14 +4,13 @@ module WhenIWork
|
|
4
4
|
class << self
|
5
5
|
|
6
6
|
def login(username, password, api_key)
|
7
|
+
client = client(skip_authentication: true)
|
7
8
|
response = client.post 'login' do |request|
|
8
9
|
request.body = { username: username, password: password, key: api_key }
|
9
10
|
end
|
10
11
|
|
11
12
|
if response.success? && response.body['token']
|
12
13
|
response.body['token']
|
13
|
-
else
|
14
|
-
raise Error::AuthenticationFailedError
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
data/lib/when-i-work/resource.rb
CHANGED
data/lib/when-i-work/shift.rb
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
2
|
|
3
3
|
describe WhenIWork::Shift do
|
4
|
+
before { authenticate }
|
4
5
|
describe "GET shifts" do
|
5
6
|
it "gets shifts" do
|
6
|
-
VCR.use_cassette("authenticate", match_requests_on: [:headers]) do
|
7
|
-
response = WhenIWork.configure(ENV['WHENIWORK_USERNAME'], ENV['WHENIWORK_PASSWORD'], ENV['WHENIWORK_API_KEY'])
|
8
|
-
expect(response).to_not be_nil
|
9
|
-
end
|
10
|
-
|
11
7
|
VCR.use_cassette("shifts", match_requests_on: [:headers]) do
|
12
8
|
response = WhenIWork::Shift.all
|
13
|
-
expect(response
|
9
|
+
expect(response).to include('start', 'end', 'shifts')
|
14
10
|
end
|
15
11
|
end
|
16
12
|
end
|
data/spec/spec_helper.rb
CHANGED
data/when-i-work.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: when-i-work 0.
|
5
|
+
# stub: when-i-work 1.0.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "when-i-work"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "1.0.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|