Class: Remit::GetPipeline::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/remit/get_pipeline.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, pipeline, options) ⇒ Pipeline

Returns a new instance of Pipeline.



53
54
55
56
57
58
59
60
# File 'lib/remit/get_pipeline.rb', line 53

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

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



39
40
41
# File 'lib/remit/get_pipeline.rb', line 39

def api
  @api
end

#parametersObject (readonly)

Returns the value of attribute parameters.



10
11
12
# File 'lib/remit/get_pipeline.rb', line 10

def parameters
  @parameters
end

#pipeline_urlObject (readonly)

Returns the value of attribute pipeline_url.



40
41
42
# File 'lib/remit/get_pipeline.rb', line 40

def pipeline_url
  @pipeline_url
end

Class Method Details

.convert_key(key) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/remit/get_pipeline.rb', line 23

def convert_key(key)
  key = key.to_s
  if key == 'return_url'
    :returnURL
  else
    key.gsub(/_(.)/) { $1.upcase }.to_sym
  end
end

.inherited(subclass) ⇒ Object

Create the parameters hash for the subclass.



14
15
16
# File 'lib/remit/get_pipeline.rb', line 14

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

.parameter(name) ⇒ Object



18
19
20
21
# File 'lib/remit/get_pipeline.rb', line 18

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.



34
35
36
# File 'lib/remit/get_pipeline.rb', line 34

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

Instance Method Details

#urlObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/remit/get_pipeline.rb', line 62

def url
  uri = URI.parse(self.pipeline_url)

  query = {}
  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)] = val
  end

  # Remove any unused optional parameters
  query.reject! { |key, value| value.nil? }

  uri.query = SignedQuery.new(self.pipeline_url, self.api.secret_key, query).to_s
  uri.to_s
end