Class: KcoRuby::Order
- Inherits:
-
Object
- Object
- KcoRuby::Order
- Includes:
- Enumerable
- Defined in:
- lib/kco_ruby/order.rb
Overview
This class represent an Order
Class Attribute Summary collapse
-
.base_uri ⇒ Object
Returns the value of attribute base_uri.
-
.content_type ⇒ Object
Returns the value of attribute content_type.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get value for key.
-
#[]=(key, value) ⇒ Object
Set a specific key to value.
-
#content_type ⇒ Object
Returns order content type.
-
#create(data) ⇒ Object
Used when creating a new order.
-
#each ⇒ Object
Implementation of Enumerable, good for iteration over data.
-
#fetch ⇒ Object
When fetching a order that already exists.
-
#initialize(connector, uri = nil) ⇒ Order
constructor
A new instance of Order.
-
#keys ⇒ Object
Keys returns all keys for order data.
-
#location ⇒ Object
Get location.
-
#location=(value) ⇒ Object
Set location.
-
#marshal ⇒ Object
Returns the order data.
-
#parse(data) ⇒ Object
Sets the order data.
-
#update(data) ⇒ Object
Used when updating order information, ie.
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_uri ⇒ Object
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_type ⇒ Object
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_type ⇒ Object
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) = { "url" => Order.base_uri, "data" => data } @connector.apply(:post, self, ) end |
#each ⇒ Object
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 |
#fetch ⇒ Object
When fetching a order that already exists
72 73 74 75 76 77 78 |
# File 'lib/kco_ruby/order.rb', line 72 def fetch = { "url" => @location } @connector.apply(:get, self, ) end |
#keys ⇒ Object
Keys returns all keys for order data
37 38 39 |
# File 'lib/kco_ruby/order.rb', line 37 def keys @data.keys end |
#location ⇒ Object
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 |
#marshal ⇒ Object
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) = { "url" => @location, "data" => data } @connector.apply(:post, self, ) end |