Class: Keypic::Client

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

Constant Summary collapse

@@methods =
{
  :new_token => "RequestNewToken",
  :validate => "RequestValidation",
  :spam => "ReportSpam",
  :check_form => "checkFormID"
}.freeze
@@types =
{
  :csv => 1,
  :json => 2,
  :php => 3,
  :xml => 4
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name, options = {}) ⇒ Client

Returns a new instance of Client.



22
23
24
25
26
27
28
29
30
# File 'lib/keypic/client.rb', line 22

def initialize(method_name, options = {})
  @method_name = method_name.to_sym

  @options = {
    "FormID" => Keypic.configuration.form_id,
    "ResponseType" => format,
    "RequestType" => method
  }.merge(options)
end

Instance Attribute Details

#last_responseObject (readonly)

Returns the value of attribute last_response.



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

def last_response
  @last_response
end

#parsed_responseObject (readonly)

Returns the value of attribute parsed_response.



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

def parsed_response
  @parsed_response
end

Instance Method Details

#formatObject



36
37
38
# File 'lib/keypic/client.rb', line 36

def format
  @format ||= @@types[Keypic.configuration.format.to_sym]
end

#invoke(options = {}) ⇒ Object



40
41
42
43
# File 'lib/keypic/client.rb', line 40

def invoke(options = {})
  request.body = @options.merge(options)
  parse_response(HTTPI.post(request))
end

#methodObject



32
33
34
# File 'lib/keypic/client.rb', line 32

def method
  @method ||= @@methods[@method_name]
end

#requestObject



45
46
47
# File 'lib/keypic/client.rb', line 45

def request
  @request ||= ::HTTPI::Request.new(:url => Keypic.configuration.endpoint)
end