shift_planning 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f32e3accb175f8bfa729f4c1e69fb8805b7deea
4
- data.tar.gz: c7788df7f61e701563b54aa09937292b5a2edc86
3
+ metadata.gz: 1e1a11b8e575ead55f9dde9c6bcce82f043753dc
4
+ data.tar.gz: f3605fe6ec37da42303aeb9c4234eaed15943d10
5
5
  SHA512:
6
- metadata.gz: 24dd987600e1da7b07b37ff0e4de3d7594b495a0694574b461cd4516a0dbe13f8e4b5a4a63db1ddba71143b716488d3729f05b3be07958194375a6d2aced6455
7
- data.tar.gz: 52f616fccf147237fc35672921a594fd4449a930ea2bc3931c167c2cbeb79ac20fc5b5afdb00034dd980a39ef7f730e49d5a9d331ad229f440478dfb35b069df
6
+ metadata.gz: 2ab7608e9bdf2fc730162419026a643fdc989b14e721be540e2ef24ff4156fb3b265d819dbea7336fa8086e3ca186ee4203e8a2ae03fdcf6cc03101203f5c3d6
7
+ data.tar.gz: 072699b5a6c490f27cbe7521c0ad6e670ee7b4d12c982383e82f8c69a15d9d1d1551d21a3249ea44f4b9ce381c89fd5fc2b51346b26027f143779aee85ef93be
@@ -5,11 +5,11 @@ require 'base64'
5
5
  module ShiftPlanning
6
6
  class Client
7
7
  def initialize(config = {})
8
- raise ArgumentError.new('Missing username') unless config.has_key? :username
8
+ raise ArgumentError.new('Missing username') unless config.key? :username
9
9
  @username = config[:username]
10
- raise ArgumentError.new('Missing password') unless config.has_key? :password
10
+ raise ArgumentError.new('Missing password') unless config.key? :password
11
11
  @password = config[:password]
12
- raise ArgumentError.new('Missing api key') unless config.has_key? :key
12
+ raise ArgumentError.new('Missing api key') unless config.key? :key
13
13
  @key = config[:key]
14
14
  @url = 'http://www.shiftplanning.com/api/'
15
15
  @headers = {
@@ -35,7 +35,17 @@ module ShiftPlanning
35
35
  @token = JSON.parse(response)["token"]
36
36
  end
37
37
 
38
- def request(api_module, request={}, method='GET')
38
+ def get(api_module, request={})
39
+ request("GET", api_module, request)
40
+ end
41
+
42
+ def update(api_module, request={})
43
+ request("UPDATE", api_module, request)
44
+ end
45
+
46
+ private
47
+
48
+ def request(method, api_module, request)
39
49
  authenticate unless authenticated?
40
50
 
41
51
  body = body_formatter({
@@ -1,3 +1,3 @@
1
1
  module ShiftPlanning
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -5,34 +5,32 @@ module ShiftPlanning
5
5
  extend self
6
6
 
7
7
  def init(options={})
8
- @@client = ShiftPlanning::Client.new(options)
8
+ @@client = Client.new(options)
9
9
  end
10
10
 
11
11
  def skills
12
- @@client.request('staff.skills')
12
+ @@client.get('staff.skills')
13
13
  end
14
14
 
15
15
  def employees
16
- @@client.request('staff.employees')
16
+ @@client.get('staff.employees')
17
17
  end
18
18
 
19
19
  def employee(employee_id)
20
- @@client.request('staff.employee', "id" => employee_id)
20
+ @@client.get('staff.employee', "id" => employee_id)
21
21
  end
22
22
 
23
23
  def add_skill(employee_id, skill_id)
24
- args = {
24
+ @@client.update('staff.employee', {
25
25
  "id" => employee_id,
26
26
  "addskill" => skill_id
27
- }
28
- @@client.request('staff.employee', args, "UPDATE")
27
+ })
29
28
  end
30
29
 
31
30
  def remove_skill(employee_id, skill_id)
32
- args = {
31
+ @@client.update('staff.employee', {
33
32
  "id" => employee_id,
34
33
  "removeskill" => skill_id
35
- }
36
- @@client.request('staff.employee', args, "UPDATE")
34
+ })
37
35
  end
38
36
  end
@@ -12,6 +12,29 @@ describe 'Client' do
12
12
  .to_return(:status => 200, :body => "{\"token\":\"1714d482a0f3a5e3472fb51c481dc571fd6724e1\"}", :headers => {})
13
13
  end
14
14
 
15
+ describe '#initialize' do
16
+ it 'username is a required field' do
17
+ err = -> {
18
+ ShiftPlanning::Client.new(:password => '', :key => '')
19
+ }.must_raise ArgumentError
20
+ err.message.must_match /username/
21
+ end
22
+
23
+ it 'password is a required field' do
24
+ err = -> {
25
+ ShiftPlanning::Client.new(:username => '', :key => '')
26
+ }.must_raise ArgumentError
27
+ err.message.must_match /password/
28
+ end
29
+
30
+ it 'key is a required field' do
31
+ err = -> {
32
+ ShiftPlanning::Client.new(:username => '', :password => '')
33
+ }.must_raise ArgumentError
34
+ err.message.must_match /key/
35
+ end
36
+ end
37
+
15
38
  describe '#authenticate' do
16
39
  it 'requests auth token and saves it' do
17
40
  @client.authenticate
@@ -19,18 +42,27 @@ describe 'Client' do
19
42
  end
20
43
  end
21
44
 
22
- describe '#request' do
45
+ describe '#get' do
46
+ it 'authenticates and makes api request' do
47
+ stub_request(:post, "http://www.shiftplanning.com/api/")
48
+ .with(:body => {"data"=>"{\"token\":\"1714d482a0f3a5e3472fb51c481dc571fd6724e1\",\"method\":\"GET\",\"module\":\"staff.employee\",\"request\":{\"id\":1}}"}, :headers => {'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'www.shiftplanning.com', 'User-Agent'=>'RubyHTTPGem/0.5.0'})
49
+ .to_return(:status => 200, :body => "{\"id\":\"1\"}", :headers => {})
50
+ employee = @client.get('staff.employee', "id" => 1)
51
+ assert 1, employee[:id]
52
+ end
53
+ end
54
+
55
+ describe '#update' do
23
56
  it 'authenticates and makes api request' do
24
57
  stub_request(:post, "http://www.shiftplanning.com/api/")
25
58
  .with(:body => {"data"=>"{\"token\":\"1714d482a0f3a5e3472fb51c481dc571fd6724e1\",\"method\":\"UPDATE\",\"module\":\"staff.employee\",\"request\":{\"id\":1,\"addskill\":2}}"}, :headers => {'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'www.shiftplanning.com', 'User-Agent'=>'RubyHTTPGem/0.5.0'})
26
59
  .to_return(:status => 200, :body => "{\"id\":\"1\"}", :headers => {})
27
60
 
28
- args = {
61
+ employee = @client.update('staff.employee', {
29
62
  "id" => 1,
30
63
  "addskill" => 2
31
- }
32
- @client.request('staff.employee', args, "UPDATE")
33
- assert true
64
+ })
65
+ assert 1, employee[:id]
34
66
  end
35
67
  end
36
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shift_planning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Mercier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-19 00:00:00.000000000 Z
11
+ date: 2014-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http