Class: ShiftPlanning::Client
- Inherits:
-
Object
- Object
- ShiftPlanning::Client
- Defined in:
- lib/shift_planning/client.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
- #authenticated? ⇒ Boolean
- #create(api_module, request = {}) ⇒ Object
- #delete(api_module, request = {}) ⇒ Object
- #get(api_module, request = {}) ⇒ Object
-
#initialize(config = {}) ⇒ Client
constructor
A new instance of Client.
- #update(api_module, request = {}) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/shift_planning/client.rb', line 7 def initialize(config = {}) raise ArgumentError.new('Missing username') unless config.key? :username @username = config[:username] raise ArgumentError.new('Missing password') unless config.key? :password @password = config[:password] raise ArgumentError.new('Missing api key') unless config.key? :key @key = config[:key] @url = 'http://www.shiftplanning.com/api/' @headers = { "Content-Type" => "application/x-www-form-urlencoded" } end |
Instance Method Details
#authenticate ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/shift_planning/client.rb', line 24 def authenticate body = body_formatter({ "key" => @key, "request" => { "module" => "staff.login", "method" => "GET", "username" => @username, "password" => @password } }) response = HTTP.with(@headers).post(@url, body) @token = JSON.parse(response)["token"] end |
#authenticated? ⇒ Boolean
20 21 22 |
# File 'lib/shift_planning/client.rb', line 20 def authenticated? !@token.nil? end |
#create(api_module, request = {}) ⇒ Object
42 43 44 |
# File 'lib/shift_planning/client.rb', line 42 def create(api_module, request={}) request("CREATE", api_module, request) end |
#delete(api_module, request = {}) ⇒ Object
50 51 52 |
# File 'lib/shift_planning/client.rb', line 50 def delete(api_module, request={}) request("DELETE", api_module, request) end |
#get(api_module, request = {}) ⇒ Object
38 39 40 |
# File 'lib/shift_planning/client.rb', line 38 def get(api_module, request={}) request("GET", api_module, request) end |
#update(api_module, request = {}) ⇒ Object
46 47 48 |
# File 'lib/shift_planning/client.rb', line 46 def update(api_module, request={}) request("UPDATE", api_module, request) end |