Class: Teemill::BaseResource

Inherits:
Object
  • Object
show all
Includes:
AuthenticatedRequestHandler
Defined in:
lib/resources/base_resource.rb

Direct Known Subclasses

CustomProduct

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AuthenticatedRequestHandler

#authenticated_request_headers, #base_url, #send_get_request, #send_post_request, #send_request

Class Method Details

.create(options) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/resources/base_resource.rb', line 7

def self.create(options)
  obj = new

  Teemill::Debug.log("Creating: #{obj.class.name}", 'cyan')

  raise Teemill::InvalidRequestError, 'No create request exists for this resource' unless obj.create_resource_url

  response = obj.send_post_request(
    obj.create_resource_url,
    options
  )

  obj.assign_properties(response)

  obj
end

Instance Method Details

#assign_properties(props) ⇒ Object


24
25
26
27
28
29
30
31
32
# File 'lib/resources/base_resource.rb', line 24

def assign_properties(props)
  props.each_key do |key|
    value = props[key]

    value = OpenStruct.new(value) if value.instance_of?(Hash)

    send("#{key}=", value)
  end
end