Class: Ifns::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ifns/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



5
6
7
8
# File 'lib/ifns/client.rb', line 5

def initialize(options)
  @data = OpenStruct.new(options)
  validate_keys
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/ifns/client.rb', line 3

def data
  @data
end

Instance Method Details

#create_ticketObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/ifns/client.rb', line 32

def create_ticket
  caching(key: "ifns:ticket_id:#{data.id}", expire: 60.seconds) do
    response = connection.post('/api/v1/tickets') do |req|
      req.headers['Content-Type'] = 'application/json'
      req.headers['X-Auth-Token'] = Ifns.configuration.token
      req.body = params.to_json
    end
    Responses::Ticket.new(response)
  end
end

#create_validationObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/ifns/client.rb', line 14

def create_validation
  caching(key: "ifns:validation_id:#{data.id}", expire: 60.seconds) do
    response = connection.post('/api/v1/validations') do |req|
      req.headers['Content-Type'] = 'application/json'
      req.headers['X-Auth-Token'] = Ifns.configuration.token
      req.body = params.to_json
    end
    Responses::Validation.new(response)
  end
end

#find_ticketObject



43
44
45
46
47
48
# File 'lib/ifns/client.rb', line 43

def find_ticket
  response = connection.get("/api/v1/tickets/#{create_ticket.id}") do |req|
    req.headers['X-Auth-Token'] = Ifns.configuration.token
  end
  Responses::Ticket.new(response)
end

#find_validationObject



25
26
27
28
29
30
# File 'lib/ifns/client.rb', line 25

def find_validation
  response = connection.get("/api/v1/validations/#{create_validation.id}") do |req|
    req.headers['X-Auth-Token'] = Ifns.configuration.token
  end
  Responses::Validation.new(response)
end

#paramsObject



10
11
12
# File 'lib/ifns/client.rb', line 10

def params
  { fn: data.fn, fd: data.fd, fpd: data.fpd, sum: data.sum, date: data.date, type_operation: data.type_operation }
end