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, options) ⇒ Pipeline

Returns a new instance of Pipeline.



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

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.



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

def api
  @api
end

#parametersObject (readonly)

Returns the value of attribute parameters.



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

def parameters
  @parameters
end

Class Method Details

.convert_key(key) ⇒ Object



22
23
24
# File 'lib/remit/get_pipeline.rb', line 22

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

.inherited(subclass) ⇒ Object

Create the parameters hash for the subclass.



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

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

.parameter(name) ⇒ Object



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

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.



28
29
30
# File 'lib/remit/get_pipeline.rb', line 28

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

Instance Method Details

#urlObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/remit/get_pipeline.rb', line 56

def url
  uri = URI.parse(@api.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.to_s)] = val
  end

  # Remove any unused optional parameters
  query.reject! { |key, value| value.nil? || (value.is_a?(String) && value.empty?) }

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