Module: EwayRapid::Message::RestProcess

Instance Method Summary collapse

Instance Method Details

#do_get(url, api_key, password) ⇒ Object

Call restful web service with get method

Parameters:

  • url (String)

    rapid endpoint url

  • api_key (String)

    rapid api key

  • password (String)

    rapid password



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/eway_rapid/message/process/rest_process.rb', line 42

def do_get(url, api_key, password)
  begin
    RestClient::Request.new(
        :method => :get,
        :url => url,
        :user => api_key,
        :password => password,
        :headers => {
            :accept => :json,
            :content_type => :json,
            :user_agent => get_user_agent
        }
    ).execute
  rescue SocketError => e
    raise Exceptions::CommunicationFailureException.new(e.to_s)
  rescue RestClient::Exception => e
    if e.http_code == 401 || e.http_code == 403 || e.http_code == 404
      raise Exceptions::AuthenticationFailureException.new(e.to_s)
    else
      raise Exceptions::SystemErrorException.new(e.to_s)
    end
  end
end

#do_post(url, api_key, password, request) ⇒ Object

Call restful web service with post method

Parameters:

  • url (String)

    rapid endpoint url

  • api_key (String)

    rapid api key

  • password (String)

    rapid password

  • request (String)

    object to post



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/eway_rapid/message/process/rest_process.rb', line 11

def do_post(url, api_key, password, request)
  begin
    RestClient::Request.execute(
      :method => :post,
      :url => url,
      :user => api_key,
      :password => password,
      :payload => request.to_json,
      :timeout => 9000000,
      :headers => {
          :accept => :json,
          :content_type => :json,
          :user_agent => get_user_agent
      }
    )
  rescue SocketError => e
    raise Exceptions::CommunicationFailureException.new(e.to_s)
  rescue RestClient::Exception => e
    if e.http_code == 401 || e.http_code == 403 || e.http_code == 404
      raise Exceptions::AuthenticationFailureException.new(e.to_s)
    else
      raise Exceptions::SystemErrorException.new(e.to_s)
    end
  end
end