Sha256: 739329b687aaec9a934880dab1b9a65b7185bd3882884af4eaecb91735b62cb4

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

module Xcal
  module Parktronic
    module Routes

      module CommandNotifications

        # Fetches remote commands
        #
        # ==== Parameters
        # * +page+ page number, defaults to 1
        # * +per_page+ per page value, defaults to 100
        #
        # ==== Examples
        #   api.get_paged_command_notifications
        #   api.command_notifications
        def get_paged_command_notifications(args = {})
          args.merge!(access_token: access_token)
          response = http.get("/#{api_version}/command_notifications?#{URI.encode_www_form(args)}")

          generic_response = Xcal::Parktronic::GenericResponse.new(response.body)
          if response.code == '200' && generic_response.has_key?(:remote_commands)
            generic_response.remote_commands.map { |command| Xcal::Parktronic::GenericResponse.new(command.remote_command, self) }
          else
            generic_response
          end

          # TODO Add caching
        end
        alias :command_notifications :get_paged_command_notifications


        # Set inactive remote command
        #
        # ==== Parameters
        # * +id+ remote command ID
        #
        # ==== Examples
        #   api.update_command_notification(1)
        #   api.set_inactive_command_notification(1)
        def update_command_notification(id)
          begin
            request = Net::HTTP::Patch.new("/#{api_version}/command_notifications/#{id}", 'Content-Type' => 'application/json')
          rescue # ruby 1.9.2
            request = Net::HTTP::Put.new("/#{api_version}/command_notifications/#{id}", 'Content-Type' => 'application/json')
          end
          request.body = { access_token: access_token }.to_json

          response = http.start { |net| net.request(request) }
          Xcal::Parktronic::GenericResponse.new(response.body)
        end
        alias :set_inactive_command_notification :update_command_notification
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xcal-parktronic-1.0.0 lib/xcal/parktronic/routes/command_notifications.rb