Class: Remotely::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/remotely/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Application

Returns a new instance of Application.



5
6
7
8
# File 'lib/remotely/application.rb', line 5

def initialize(name, &block)
  @name = name
  instance_eval(&block)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/remotely/application.rb', line 3

def name
  @name
end

Instance Method Details

#authorization(type = nil, token = nil) ⇒ Object

Set or get a custom Authorization header.

- As seen here: https://github.com/lostisland/faraday/blob/master/lib/faraday/connection.rb#L227

Parameters:

  • type (String) (defaults to: nil)
    • The String authorization type.

  • token (String|Hash) (defaults to: nil)
    • The String or Hash token. A String value is taken literally, and a Hash is encoded into comma separated key/value pairs.



46
47
48
49
# File 'lib/remotely/application.rb', line 46

def authorization(type=nil, token=nil)
  return @authorization unless type && token
  @authorization = [type, token]
end

#basic_auth(user = nil, password = nil) ⇒ Object

Set or get BasicAuth credentials.

Parameters:

  • user (String) (defaults to: nil)

    BasicAuth user

  • password (String) (defaults to: nil)

    BasicAuth password



24
25
26
27
# File 'lib/remotely/application.rb', line 24

def basic_auth(user=nil, password=nil)
  return @basic_auth unless user && password
  @basic_auth = [user, password]
end

#connectionObject

Connection to the application (with BasicAuth if it was set).



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/remotely/application.rb', line 61

def connection
  return unless @url

  @connection ||= Faraday::Connection.new(@url) do |b|
    middleware.each { |m, opts| b.use(m, opts) }
    b.request :url_encoded
    b.adapter :net_http
  end
  
  @connection.basic_auth(*@basic_auth)        if @basic_auth
  @connection.token_auth(*@token_auth)        if @token_auth
  @connection.authorization(*@authorization)  if @authorization
  @connection
end

#middlewareObject



55
56
57
# File 'lib/remotely/application.rb', line 55

def middleware
  @middleware ||= []
end

#token_auth(token = nil, options = {}) ⇒ Object

Set or get the Authorization header.

- As seen here: https://github.com/lostisland/faraday/blob/master/lib/faraday/connection.rb#L204

Parameters:

  • token (String) (defaults to: nil)
    • The String token.

  • options (Hash) (defaults to: {})
    • Optional Hash of extra token options.



35
36
37
38
# File 'lib/remotely/application.rb', line 35

def token_auth(token=nil, options={})
  return @token_auth unless token
  @token_auth = [token, options]
end

#url(url = nil) ⇒ Object

Set or get the applications base url.

Parameters:

  • url (String) (defaults to: nil)

    Base url to the appplication



14
15
16
17
# File 'lib/remotely/application.rb', line 14

def url(url=nil)
  return @url unless url
  @url = URI.parse(set_scheme(url)).to_s
end

#use_middleware(klass, options = {}) ⇒ Object



51
52
53
# File 'lib/remotely/application.rb', line 51

def use_middleware(klass, options = {})
  middleware << [klass, options]
end