Class: Remit::GetPipeline::Pipeline

Inherits:
Object
  • Object
show all
Includes:
Signature
Defined in:
lib/remit2/get_pipeline.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Signature

#sign, #string_to_sign, #urlencode

Constructor Details

#initialize(api, options) ⇒ Pipeline

Returns a new instance of Pipeline.



47
48
49
50
51
52
53
# File 'lib/remit2/get_pipeline.rb', line 47

def initialize(api, options)
  @api = api
  
  options.each do |k,v|
    self.send("#{k}=", v)
  end
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



32
33
34
# File 'lib/remit2/get_pipeline.rb', line 32

def api
  @api
end

#parametersObject (readonly)

Returns the value of attribute parameters.



8
9
10
# File 'lib/remit2/get_pipeline.rb', line 8

def parameters
  @parameters
end

Class Method Details

.convert_key(key) ⇒ Object



21
22
23
# File 'lib/remit2/get_pipeline.rb', line 21

def convert_key(key)
  key.to_s.gsub(/_(.)/) { $1.upcase }.to_sym
end

.inherited(subclass) ⇒ Object

Create the parameters hash for the subclass.



12
13
14
# File 'lib/remit2/get_pipeline.rb', line 12

def inherited(subclass) #:nodoc:
  subclass.instance_variable_set('@parameters', [])
end

.parameter(name) ⇒ Object



16
17
18
19
# File 'lib/remit2/get_pipeline.rb', line 16

def parameter(name)
  attr_accessor name
  @parameters << name
end

.parametersObject

Returns a hash of all of the parameters for this request, including those that are inherited.



27
28
29
# File 'lib/remit2/get_pipeline.rb', line 27

def parameters #:nodoc:
  (superclass.respond_to?(:parameters) ? superclass.parameters : []) + @parameters
end

Instance Method Details

#urlObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/remit2/get_pipeline.rb', line 55

def url
  uri = URI.parse(@api.pipeline_url)
  
  query = {
    "signatureVersion" => "2",
    "signatureMethod" => "HmacSHA256",
    "version" => "2009-01-09"
  }
  
  self.class.parameters.each do |p|
    val = self.send(p)
    
    # Convert Time values to seconds from Epoch
    val = val.to_i if val.is_a?(Time)
    
    query[self.class.convert_key(p.to_s)] = val
  end

  # Remove any unused optional parameters
  query.reject! { |key, value| value.nil? || (value.is_a?(String) && value.empty?) }
  
  signature = sign(@api.secret_key, @api.pipeline_url, "GET", query)
  uri.query = query.merge('signature' => signature).collect {|k,v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}"}.join("&")
  
  uri.to_s
end