Class: Octoprint::API

Inherits:
Object
  • Object
show all
Defined in:
lib/octoprint/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, api_key) ⇒ API

Returns a new instance of API.



6
7
8
9
# File 'lib/octoprint/api.rb', line 6

def initialize(url, api_key)
  @url = url
  @api_key = api_key
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, **args, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/octoprint/api.rb', line 11

def method_missing(name, **args, &block)
  super unless name_qualified_for_api_request?(name)

  http_verb = args[:method] || :get
  response = _connection.public_send http_verb, generate_api_path(name)

  super if response.status == 404
  raise Octoprint::ResponseError.new(response.status, response.body) unless (200..299).include?(response.status)

  parse(response.body)
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/octoprint/api.rb', line 23

def respond_to_missing?(method_name, include_private = false)
  return super unless name_qualified_for_api_request?(method_name)
  
  super || _connection.get(generate_api_path(method_name))
end