Sha256: 7585df5d8b8741e6f282870d1a4ed25f905b1841c8f3e1a723f82d8675c95255

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

require 'rest_client'
require 'json'

module CobotClient
  class ApiClient
    include UrlHelper

    def initialize(access_token)
      @access_token = access_token
    end

    def get_resources(subdomain)
      get subdomain, '/resources'
    end

    def create_booking(subdomain, resource_id, attributes)
      post subdomain, "/resources/#{resource_id}/bookings", attributes
    end

    def update_booking(subdomain, id, attributes)
      put subdomain, "/bookings/#{id}", attributes
    end

    def delete_booking(subdomain, id)
      delete subdomain, "/bookings/#{id}"
    end

    def put(subdomain, path, params)
      JSON.parse RestClient.put(cobot_url(subdomain, "/api#{path}"), params, auth_headers).body,
        symbolize_names: true
    end

    def delete(subdomain, path)
      RestClient.delete(cobot_url(subdomain, "/api#{path}"), auth_headers)
    end

    def post(subdomain, path, params)
      JSON.parse RestClient.post(cobot_url(subdomain, "/api#{path}"), params, auth_headers).body,
        symbolize_names: true
    end

    def get(subdomain, path, params = {})
      JSON.parse(
        RestClient.get(cobot_url(subdomain, "/api#{path}", params: params), auth_headers).body,
        symbolize_names: true
      )
    end

    def auth_headers
      {'Authorization' => "Bearer #{@access_token}"}
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cobot_client-0.6.7 lib/cobot_client/api_client.rb
cobot_client-0.6.6 lib/cobot_client/api_client.rb
cobot_client-0.6.5 lib/cobot_client/api_client.rb
cobot_client-0.6.4 lib/cobot_client/api_client.rb
cobot_client-0.6.3 lib/cobot_client/api_client.rb
cobot_client-0.6.2 lib/cobot_client/api_client.rb
cobot_client-0.6.1 lib/cobot_client/api_client.rb
cobot_client-0.6.0 lib/cobot_client/api_client.rb