Class: Wheretocard::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ Client

Initializer to transform a Hash into an Client object

Parameters:

  • args (Hash) (defaults to: nil)


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wheretocard/client.rb', line 18

def initialize(args=nil)
  required_args = [:username, :password, :client_code, :case_code]
  for arg in required_args
    if args.nil? || args[arg].nil?
      raise WheretocardError.new(self), "Insufficient login credentials. Please provide @username, @password, @client_code and @case_code"
    end
  end

  return if args.nil?
  args.each do |k,v|
    instance_variable_set("@#{k}", v) unless v.nil?
  end
end

Instance Attribute Details

#case_codeString

Returns Your Wheretocard case code.

Returns:

  • (String)

    Your Wheretocard case code



11
12
13
# File 'lib/wheretocard/client.rb', line 11

def case_code
  @case_code
end

#client_codeString

Returns Your Wheretocard client code.

Returns:

  • (String)

    Your Wheretocard client code



9
10
11
# File 'lib/wheretocard/client.rb', line 9

def client_code
  @client_code
end

#passwordString

Returns Your Wheretocard password.

Returns:

  • (String)

    Your Wheretocard password



7
8
9
# File 'lib/wheretocard/client.rb', line 7

def password
  @password
end

#usernameObject

Note:

The is a required parameter.



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

def username
  @username
end

Instance Method Details

#check_credentials(product_code = "") ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/wheretocard/client.rb', line 32

def check_credentials(product_code="")
  o = order
  o.add_line_item(
    price: 0, 
    description: 'Checking credentials [TEST]', 
    ticket_ref: 1234,
    valid_from: Time.now,
    valid_until: Time.now + 24*31*3600,
    product_code: product_code, 
    quantity: 0
  )
  begin
    o.submit
  rescue WheretocardError => e
    # return true if the error raised is only about the
    # number of tickets (cannot be zero)
    e.to_s.include?("OI_0210")
  end
  
end

#order(args = {}) ⇒ Object Also known as: orders, new_order, add_order

def order_requests

Wheretocard::Order

end alias :order_request :order_requests



58
59
60
# File 'lib/wheretocard/client.rb', line 58

def order(args={})
  Wheretocard::Order.new({client: self}.merge(args))
end