Class: KcoRuby::Order

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/kco_ruby/order.rb

Overview

This class represent an Order

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connector, uri = nil) ⇒ Order

Returns a new instance of Order.



10
11
12
13
14
# File 'lib/kco_ruby/order.rb', line 10

def initialize(connector, uri=nil)
  @connector =connector
  self.location = uri
  @data = {}
end

Class Attribute Details

.base_uriObject

Returns the value of attribute base_uri.



7
8
9
# File 'lib/kco_ruby/order.rb', line 7

def base_uri
  @base_uri
end

.content_typeObject

Returns the value of attribute content_type.



7
8
9
# File 'lib/kco_ruby/order.rb', line 7

def content_type
  @content_type
end

Instance Method Details

#[](key) ⇒ Object

Get value for key



27
28
29
# File 'lib/kco_ruby/order.rb', line 27

def [](key)
  @data[key.to_s]
end

#[]=(key, value) ⇒ Object

Set a specific key to value



32
33
34
# File 'lib/kco_ruby/order.rb', line 32

def []=(key, value)
  @data[key.to_s]=value
end

#content_typeObject

Returns order content type



47
48
49
# File 'lib/kco_ruby/order.rb', line 47

def content_type
  Order.content_type
end

#create(data) ⇒ Object

Used when creating a new order



62
63
64
65
66
67
68
69
# File 'lib/kco_ruby/order.rb', line 62

def create(data)
  options = {
      "url" => Order.base_uri,
      "data" => data
  }

  @connector.apply(:post, self, options)
end

#eachObject

Implementation of Enumerable, good for iteration over data



42
43
44
# File 'lib/kco_ruby/order.rb', line 42

def each
  @data.each {|key, value| yield key, value}
end

#fetchObject

When fetching a order that already exists



72
73
74
75
76
77
78
# File 'lib/kco_ruby/order.rb', line 72

def fetch
  options = {
      "url" => @location
  }

  @connector.apply(:get, self, options)
end

#keysObject

Keys returns all keys for order data



37
38
39
# File 'lib/kco_ruby/order.rb', line 37

def keys
  @data.keys
end

#locationObject

Get location



22
23
24
# File 'lib/kco_ruby/order.rb', line 22

def location
  @location
end

#location=(value) ⇒ Object

Set location



17
18
19
# File 'lib/kco_ruby/order.rb', line 17

def location=(value)
  @location = value.to_s if value
end

#marshalObject

Returns the order data



57
58
59
# File 'lib/kco_ruby/order.rb', line 57

def marshal
  @data
end

#parse(data) ⇒ Object

Sets the order data



52
53
54
# File 'lib/kco_ruby/order.rb', line 52

def parse(data)
  @data = data
end

#update(data) ⇒ Object

Used when updating order information, ie. order status completed



81
82
83
84
85
86
87
88
# File 'lib/kco_ruby/order.rb', line 81

def update(data)
  options = {
      "url" => @location,
      "data" => data
  }

  @connector.apply(:post, self, options)
end