Class: PrintNode::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/print_node/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client


12
13
14
15
16
# File 'lib/print_node/client.rb', line 12

def initialize(options={})
  @username      = options[:username]      || ENV['PRINTUSERNAME']
  @password      = options[:password]      || ENV['PASSWORD']
  @address       = 'https://api.printnode.com/'
end

Instance Attribute Details

#addressObject

Returns the value of attribute address


4
5
6
# File 'lib/print_node/client.rb', line 4

def address
  @address
end

#passwordObject

Returns the value of attribute password


4
5
6
# File 'lib/print_node/client.rb', line 4

def password
  @password
end

#usernameObject

Returns the value of attribute username


4
5
6
# File 'lib/print_node/client.rb', line 4

def username
  @username
end

Class Method Details

.connectionObject


8
9
10
# File 'lib/print_node/client.rb', line 8

def self.connection
  @connection ||= new.connection
end

Instance Method Details

#connectionObject


18
19
20
21
22
23
24
25
# File 'lib/print_node/client.rb', line 18

def connection
  Faraday.new(url: @address) do |conn|
    conn.basic_auth @username, @password
    conn.request  :json
    conn.use      FaradayMiddleware::RaiseHttpException
    conn.adapter  Faraday.default_adapter
  end
end