Class: Xdelivery::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/xdelivery/callback.rb

Constant Summary collapse

PARAM_KEYS =
[ :action, :title, :desc, :provider, :created_at ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(merchant_no, access_key, params) ⇒ Callback

Returns a new instance of Callback.



7
8
9
10
11
12
13
14
15
# File 'lib/xdelivery/callback.rb', line 7

def initialize(merchant_no, access_key, params)
  self.params = PARAM_KEYS.map do |key|
    [ key, params[key] ]
  end.to_h

  self.check_code = params[:check_code]
  self.merchant_no = merchant_no
  self.access_key = access_key
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



3
4
5
# File 'lib/xdelivery/callback.rb', line 3

def access_key
  @access_key
end

#check_codeObject

Returns the value of attribute check_code.



3
4
5
# File 'lib/xdelivery/callback.rb', line 3

def check_code
  @check_code
end

#merchant_noObject

Returns the value of attribute merchant_no.



3
4
5
# File 'lib/xdelivery/callback.rb', line 3

def merchant_no
  @merchant_no
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/xdelivery/callback.rb', line 3

def params
  @params
end

Instance Method Details

#actionObject



21
22
23
# File 'lib/xdelivery/callback.rb', line 21

def action
  params[:action]
end

#created_atObject



37
38
39
40
41
42
43
44
45
# File 'lib/xdelivery/callback.rb', line 37

def created_at
  if params[:created_at] == ''
    nil
  elsif Time.respond_to?(:zone)
    Time.zone.parse(params[:created_at])
  else
    Time.parse(params[:created_at])
  end
end

#descObject



29
30
31
# File 'lib/xdelivery/callback.rb', line 29

def desc
  params[:desc]
end

#providerObject



33
34
35
# File 'lib/xdelivery/callback.rb', line 33

def provider
  params[:provider]
end

#titleObject



25
26
27
# File 'lib/xdelivery/callback.rb', line 25

def title
  params[:title]
end

#valid?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/xdelivery/callback.rb', line 17

def valid?
  check_code == check_code!
end