Module: EwayRapid::Message::RestProcess

Instance Method Summary collapse

Instance Method Details

#do_get(url, api_key, password, version) ⇒ Object

Call restful web service with get method

Parameters:

  • url (String)

    rapid endpoint url

  • api_key (String)

    rapid api key

  • password (String)

    rapid password



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

def do_get(url, api_key, password, version)
  begin
    RestClient::Request.new(
        :method => :get,
        :url => url,
        :user => api_key,
        :password => password,
        :ssl_version => 'TLSv1_2',
        :headers => {
            :accept => :json,
            :content_type => :json,
            :user_agent => get_user_agent,
            :'X-EWAY-APIVERSION' => version
        }
    ).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, version, 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
36
37
# File 'lib/eway_rapid/message/process/rest_process.rb', line 11

def do_post(url, api_key, password, version, request)
  begin
    RestClient::Request.execute(
      :method => :post,
      :url => url,
      :user => api_key,
      :password => password,
      :payload => request.to_json,
      :timeout => 9000000,
      :ssl_version => 'TLSv1_2',
      :headers => {
          :accept => :json,
          :content_type => :json,
          :user_agent => get_user_agent,
          :'X-EWAY-APIVERSION' => version
      }
    )
  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