when-i-work 0.2.0 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f57220311944a37896ad65038251c3a9a699802b
4
- data.tar.gz: 5ea8f6d27df0918ee1894e5cc4921af680cfcdef
3
+ metadata.gz: c03cba8607c9af712614d7166cf0afea2e94233c
4
+ data.tar.gz: c04241572ebe7b4ecb8ebc8091f1a4f598ffb1e0
5
5
  SHA512:
6
- metadata.gz: cb5aef9fe17336ed5520bf6dc5f222a27b9f86e56017a8164cb17881ddfa2944f1bc11cb5baa0e4946773c85406a3f8397eac8844f5e98f9ecee174bb5c939c4
7
- data.tar.gz: 5c39464bed10da1a9b22e25d218aa0f7d5eab7a10d4f1d31053fc701ffc0e18443a26541bb8f6db8bb0d6019c62af92ee00b7c14ec1715b1e8f743851cd769af
6
+ metadata.gz: 60cd6c7c53eae30036bd8c17e8191ca2f07bb115974232cadd2ace783d7fd6219d1820b058708e558d9d66db6c8b54977e8ebb7827b5ab87aa6e1a8ced5605c0
7
+ data.tar.gz: 52f211b2e53dc97e5c888f3a7919613cbec095f060a91a3faae8b8f687b44da4668e86673cc6c8b918bde8dc702b85ad3b5b75bbff00c3da12b749a3ecb65e13
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 1.0.0
@@ -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
- @token = Authentication.login(username, password, api_key)
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' => @token } if @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
 
@@ -1,7 +1,7 @@
1
1
  module WhenIWork
2
2
  class Resource
3
- def self.client
4
- WhenIWork.client
3
+ def self.client(options = {})
4
+ WhenIWork.client(options)
5
5
  end
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module WhenIWork
2
2
  class Shift < Resource
3
3
  def self.all(options = {})
4
- client.get 'shifts', options
4
+ client.get('shifts', options).body
5
5
  end
6
6
  end
7
7
  end
@@ -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.body).to include('start', 'end', 'shifts')
9
+ expect(response).to include('start', 'end', 'shifts')
14
10
  end
15
11
  end
16
12
  end
@@ -8,6 +8,10 @@ module SimpleCov::Configuration
8
8
  end
9
9
  end
10
10
 
11
+ def authenticate
12
+ WhenIWork.configure(ENV['WHENIWORK_USERNAME'], ENV['WHENIWORK_PASSWORD'], ENV['WHENIWORK_API_KEY'])
13
+ end
14
+
11
15
  SimpleCov.configure do
12
16
  clean_filters
13
17
  load_adapter 'test_frameworks'
@@ -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.2.0 ruby lib
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.2.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"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: when-i-work
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ingmaras Keleras