Class: Airplay::Connection

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/airplay/connection.rb,
lib/airplay/connection/persistent.rb,
lib/airplay/connection/authentication.rb

Overview

Public: The class that handles all the outgoing basic HTTP connections

Defined Under Namespace

Classes: Authentication, Persistent, Response

Constant Summary collapse

PasswordRequired =
Class.new(StandardError)
WrongPassword =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(device, options = {}) ⇒ Connection

Returns a new instance of Connection.



15
16
17
18
19
# File 'lib/airplay/connection.rb', line 15

def initialize(device, options = {})
  @device = device
  @options = options
  @logger = Airplay::Logger.new("airplay::connection")
end

Instance Method Details

#closeObject

Public: Closes the opened connection

Returns nothing



34
35
36
37
# File 'lib/airplay/connection.rb', line 34

def close
  persistent.close
  @_persistent = nil
end

#get(resource, headers = {}) ⇒ Object

Public: Executes a GET to a resource

resource - The resource on the currently active Device headers - Optional headers

Returns a response object



70
71
72
# File 'lib/airplay/connection.rb', line 70

def get(resource, headers = {})
  prepare_request(:get, resource, nil, headers)
end

#persistentObject

Public: Establishes a persistent connection to the device

Returns the persistent connection



25
26
27
28
# File 'lib/airplay/connection.rb', line 25

def persistent
  address = @options[:address] || "http://#{@device.address}"
  @_persistent ||= Airplay::Connection::Persistent.new(address, @options)
end

#post(resource, body = "", headers = {}) ⇒ Object

Public: Executes a POST to a resource

resource - The resource on the currently active Device body - The body of the action headers - Optional headers

Returns a response object



47
48
49
# File 'lib/airplay/connection.rb', line 47

def post(resource, body = "", headers = {})
  prepare_request(:post, resource, body, headers)
end

#put(resource, body = "", headers = {}) ⇒ Object

Public: Executes a PUT to a resource

resource - The resource on the currently active Device body - The body of the action headers - Optional headers

Returns a response object



59
60
61
# File 'lib/airplay/connection.rb', line 59

def put(resource, body = "", headers = {})
  prepare_request(:put, resource, body, headers)
end