Class: Runa::RemoteCode

Inherits:
Response show all
Defined in:
lib/runa/models/remote_code.rb

Constant Summary

Constants inherited from Response

Runa::Response::STATUS

Instance Attribute Summary collapse

Attributes inherited from Response

#error_code, #error_details, #error_string, #payload, #status

Instance Method Summary collapse

Methods inherited from Response

#is_successful?

Methods included from Initializable

#initialize

Instance Attribute Details

#amountObject

response/success



12
13
14
# File 'lib/runa/models/remote_code.rb', line 12

def amount
  @amount
end

#barcode_formatObject

response/success



12
13
14
# File 'lib/runa/models/remote_code.rb', line 12

def barcode_format
  @barcode_format
end

#barcode_stringObject

response/success



12
13
14
# File 'lib/runa/models/remote_code.rb', line 12

def barcode_string
  @barcode_string
end

#codeObject

response/success



12
13
14
# File 'lib/runa/models/remote_code.rb', line 12

def code
  @code
end

#expiry_dateObject

response/success



12
13
14
# File 'lib/runa/models/remote_code.rb', line 12

def expiry_date
  @expiry_date
end

#pinObject

response/success



12
13
14
# File 'lib/runa/models/remote_code.rb', line 12

def pin
  @pin
end

#typeObject

response/success



12
13
14
# File 'lib/runa/models/remote_code.rb', line 12

def type
  @type
end

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/runa/models/remote_code.rb', line 9

def url
  @url
end

Instance Method Details

#get(ctx) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/runa/models/remote_code.rb', line 15

def get(ctx)
  conn = Faraday.new(url: url) do |c|
    c.adapter :net_http
    c.use FaradayMiddleware::FollowRedirects, limit: 5
  end
  parse(conn.get("#{url}?format=json") { |r| r.headers['Accept'] = 'application/json' })
end

#parse(response) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/runa/models/remote_code.rb', line 23

def parse(response)
  super

  if is_successful?
    self.class.new(@payload['e_code'])
  else
    self
  end
end