Class: FbGraph::Order

Inherits:
Node
  • Object
show all
Defined in:
lib/fb_graph/order.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#access_token, #endpoint, #identifier

Instance Method Summary collapse

Methods inherited from Node

#connection, #destroy, fetch, #fetch

Methods included from Comparison

#==

Constructor Details

#initialize(identifier, attributes = {}) ⇒ Order

Returns a new instance of Order.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fb_graph/order.rb', line 5

def initialize(identifier, attributes = {})
  super
  if app = attributes[:application]
    @application = Application.new(app[:id], app)
  end
  if from = attributes[:from]
    @from = User.new(from[:id], from)
  end
  if to = attributes[:to]
    @to = User.new(to[:id], to)
  end
  @status = attributes[:status]
  @country = attributes[:country]
  if attributes[:created_time]
    @created_time = Time.parse(attributes[:created_time]).utc
  end
  if attributes[:updated_time]
    @updated_time = Time.parse(attributes[:updated_time]).utc
  end
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



3
4
5
# File 'lib/fb_graph/order.rb', line 3

def amount
  @amount
end

#applicationObject

Returns the value of attribute application.



3
4
5
# File 'lib/fb_graph/order.rb', line 3

def application
  @application
end

#countryObject

Returns the value of attribute country.



3
4
5
# File 'lib/fb_graph/order.rb', line 3

def country
  @country
end

#created_timeObject

Returns the value of attribute created_time.



3
4
5
# File 'lib/fb_graph/order.rb', line 3

def created_time
  @created_time
end

#fromObject

Returns the value of attribute from.



3
4
5
# File 'lib/fb_graph/order.rb', line 3

def from
  @from
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'lib/fb_graph/order.rb', line 3

def status
  @status
end

#toObject

Returns the value of attribute to.



3
4
5
# File 'lib/fb_graph/order.rb', line 3

def to
  @to
end

#updated_timeObject

Returns the value of attribute updated_time.



3
4
5
# File 'lib/fb_graph/order.rb', line 3

def updated_time
  @updated_time
end

Instance Method Details

#canceled!(options = {}) ⇒ Object



39
40
41
# File 'lib/fb_graph/order.rb', line 39

def canceled!(options = {})
  update options.merge(:status => :canceled)
end

#refunded!(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/fb_graph/order.rb', line 30

def refunded!(options = {})
  defaults = {
    :status => :refunded,
    :message => "Refunded", # message is currently required by facebook in a refund
    :refund_funding_source => true
  }
  update defaults.merge(options)
end

#settled!(options = {}) ⇒ Object



26
27
28
# File 'lib/fb_graph/order.rb', line 26

def settled!(options = {})
  update options.merge(:status => :settled)
end

#update(attributes = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fb_graph/order.rb', line 43

def update(attributes = {})
  _attributes_ = attributes.dup
  params = {
    :access_token => self.access_token,
    :status => _attributes_.delete(:status),
    :message => _attributes_.delete(:message),
    :refund_funding_source => _attributes_.delete(:refund_funding_source),
    :refund_reason => _attributes_.delete(:refund_reason),
    :params => _attributes_.to_json
  }
  post params
end