shift_planning 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f32e3accb175f8bfa729f4c1e69fb8805b7deea
4
+ data.tar.gz: c7788df7f61e701563b54aa09937292b5a2edc86
5
+ SHA512:
6
+ metadata.gz: 24dd987600e1da7b07b37ff0e4de3d7594b495a0694574b461cd4516a0dbe13f8e4b5a4a63db1ddba71143b716488d3729f05b3be07958194375a6d2aced6455
7
+ data.tar.gz: 52f616fccf147237fc35672921a594fd4449a930ea2bc3931c167c2cbeb79ac20fc5b5afdb00034dd980a39ef7f730e49d5a9d331ad229f440478dfb35b069df
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p353
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ before_install: gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shift_planning.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tyler Mercier
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,49 @@
1
+ # ShiftPlanning
2
+
3
+ Ruby gem for the [Shift Planning API](http://www.shiftplanning.com)
4
+
5
+ ## Status
6
+ [![Gem Version](https://badge.fury.io/rb/shift_planning.png)](http://badge.fury.io/rb/shift_planning)
7
+ [![Build Status](https://secure.travis-ci.org/tylermercier/shift_planning.png)](http://travis-ci.org/tylermercier/shift_planning)
8
+ [![Code Climate](https://codeclimate.com/github/tylermercier/shift_planning.png)](https://codeclimate.com/github/tylermercier/shift_planning)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'shift_planning'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install shift_planning
23
+
24
+ ## Usage
25
+
26
+ ShiftPlanning.init({
27
+ :username => 'username',
28
+ :password => 'password',
29
+ :key => 'api_key'
30
+ })
31
+
32
+ ShiftPlanning.skills
33
+
34
+ ShiftPlanning.employees
35
+
36
+ ShiftPlanning.employee(887992)
37
+
38
+ ShiftPlanning.add_skill(887992, 50186)
39
+
40
+ ShiftPlanning.remove_skill(887992, 50186)
41
+
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( http://github.com/<my-github-username>/ShiftPlanning/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler"
3
+ require "bundler/gem_tasks"
4
+ require 'rake/testtask'
5
+
6
+ task default: 'test'
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'lib'
10
+ t.libs << 'test'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
@@ -0,0 +1,57 @@
1
+ require 'http'
2
+ require 'json'
3
+ require 'base64'
4
+
5
+ module ShiftPlanning
6
+ class Client
7
+ def initialize(config = {})
8
+ raise ArgumentError.new('Missing username') unless config.has_key? :username
9
+ @username = config[:username]
10
+ raise ArgumentError.new('Missing password') unless config.has_key? :password
11
+ @password = config[:password]
12
+ raise ArgumentError.new('Missing api key') unless config.has_key? :key
13
+ @key = config[:key]
14
+ @url = 'http://www.shiftplanning.com/api/'
15
+ @headers = {
16
+ "Content-Type" => "application/x-www-form-urlencoded"
17
+ }
18
+ end
19
+
20
+ def authenticated?
21
+ !@token.nil?
22
+ end
23
+
24
+ def authenticate
25
+ body = body_formatter({
26
+ "key" => @key,
27
+ "request" => {
28
+ "module" => "staff.login",
29
+ "method" => "GET",
30
+ "username" => @username,
31
+ "password" => @password
32
+ }
33
+ })
34
+ response = HTTP.with(@headers).post(@url, body)
35
+ @token = JSON.parse(response)["token"]
36
+ end
37
+
38
+ def request(api_module, request={}, method='GET')
39
+ authenticate unless authenticated?
40
+
41
+ body = body_formatter({
42
+ "token" => @token,
43
+ "method" => method,
44
+ "module" => api_module,
45
+ "request" => request
46
+ })
47
+ response = HTTP.with(@headers).post(@url, body)
48
+ JSON.parse(response)
49
+ end
50
+
51
+ def body_formatter(body)
52
+ {
53
+ :body => "data=#{JSON.dump(body)}"
54
+ }
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module ShiftPlanning
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,38 @@
1
+ require "shift_planning/version"
2
+ require "shift_planning/client"
3
+
4
+ module ShiftPlanning
5
+ extend self
6
+
7
+ def init(options={})
8
+ @@client = ShiftPlanning::Client.new(options)
9
+ end
10
+
11
+ def skills
12
+ @@client.request('staff.skills')
13
+ end
14
+
15
+ def employees
16
+ @@client.request('staff.employees')
17
+ end
18
+
19
+ def employee(employee_id)
20
+ @@client.request('staff.employee', "id" => employee_id)
21
+ end
22
+
23
+ def add_skill(employee_id, skill_id)
24
+ args = {
25
+ "id" => employee_id,
26
+ "addskill" => skill_id
27
+ }
28
+ @@client.request('staff.employee', args, "UPDATE")
29
+ end
30
+
31
+ def remove_skill(employee_id, skill_id)
32
+ args = {
33
+ "id" => employee_id,
34
+ "removeskill" => skill_id
35
+ }
36
+ @@client.request('staff.employee', args, "UPDATE")
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shift_planning/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shift_planning"
8
+ spec.version = ShiftPlanning::VERSION
9
+ spec.authors = ["Tyler Mercier"]
10
+ spec.email = ["tylermercier@gmail.com"]
11
+ spec.summary = %q{Shift Planning API gem}
12
+ spec.description = %q{Shift Planning API gem}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency "http"
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "minitest-reporters"
25
+ spec.add_development_dependency "webmock"
26
+ end
@@ -0,0 +1,11 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/reporters'
3
+ require 'webmock/minitest'
4
+
5
+ Minitest::Reporters.use!(Minitest::Reporters::DefaultReporter.new(color: true))
6
+
7
+ ENV['RACK_ENV'] = 'test'
8
+
9
+ Dir[File.dirname(__FILE__) + '/../lib/*.rb'].each do |file|
10
+ require File.basename(file, File.extname(file))
11
+ end
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ describe 'Client' do
4
+ before do
5
+ @client = ShiftPlanning::Client.new({
6
+ :username => 'devapi',
7
+ :password => 'password',
8
+ :key => 'e145a81787a46fc24802f1626befb20dcd76fd7b'
9
+ })
10
+ stub_request(:post, "http://www.shiftplanning.com/api/")
11
+ .with(:body => {"data"=>"{\"key\":\"e145a81787a46fc24802f1626befb20dcd76fd7b\",\"request\":{\"module\":\"staff.login\",\"method\":\"GET\",\"username\":\"devapi\",\"password\":\"password\"}}"}, :headers => {'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'www.shiftplanning.com', 'User-Agent'=>'RubyHTTPGem/0.5.0'})
12
+ .to_return(:status => 200, :body => "{\"token\":\"1714d482a0f3a5e3472fb51c481dc571fd6724e1\"}", :headers => {})
13
+ end
14
+
15
+ describe '#authenticate' do
16
+ it 'requests auth token and saves it' do
17
+ @client.authenticate
18
+ assert @client.authenticated?
19
+ end
20
+ end
21
+
22
+ describe '#request' do
23
+ it 'authenticates and makes api request' do
24
+ stub_request(:post, "http://www.shiftplanning.com/api/")
25
+ .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
+ .to_return(:status => 200, :body => "{\"id\":\"1\"}", :headers => {})
27
+
28
+ args = {
29
+ "id" => 1,
30
+ "addskill" => 2
31
+ }
32
+ @client.request('staff.employee', args, "UPDATE")
33
+ assert true
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shift_planning
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Mercier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Shift Planning API gem
84
+ email:
85
+ - tylermercier@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .ruby-version
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/shift_planning.rb
98
+ - lib/shift_planning/client.rb
99
+ - lib/shift_planning/version.rb
100
+ - shift_planning.gemspec
101
+ - test/test_helper.rb
102
+ - test/unit/client_test.rb
103
+ homepage: ''
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.0.14
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Shift Planning API gem
127
+ test_files:
128
+ - test/test_helper.rb
129
+ - test/unit/client_test.rb