Class: Sep6Client::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(transfer_server = nil, log_file = nil) ⇒ Client

Initializes the Sep-6 Client

Parameters:

  • transfer_server;

    the SEP-6 transfer server

  • log_file;

    optional log file path



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

def initialize(transfer_server = nil, log_file = nil)

  # @string Used in the HTTP user agent (leave it as is)
  @client_name = Sep6Client::CLIENT_NAME

  # @string The current version of this SDK, used in the HTTP user agent (leave it as is)
  @client_version = Sep6Client::CLIENT_VERSION

  # @string Whalestack connect url
  @transfer_server = transfer_server ? transfer_server : Sep6Client::TRANSFER_SERVER

  # @string|nil Specifies the log file to which to write, if any.
  @log_file = log_file ? log_file : nil

end

Instance Method Details

#delete(endpoint, params = {}) ⇒ Object

Use this method to communicate with PUT endpoints

Parameters:

  • endpoint (string)

    , e.g. PUT /customer

  • params (hash) (defaults to: {})

    , a list of GET parameters to be included in the request

Returns:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/sep6_client/client.rb', line 113

def delete(endpoint, params = {})

  path = build_connect_url(endpoint)
  headers = build_headers(endpoint, 'DELETE', params)

  log "DELETE " + path + " " + params.to_s
  log headers.to_s

  begin
    response = RestClient::Request.execute(method: :delete, url: path, payload: params.to_json, headers: headers, timeout: 180)
  rescue RestClient::ExceptionWithResponse => e
    log e.http_code.to_s + " " + e.response.to_s
    return e.response
  end

  log response.code.to_s + " " + response.to_s

  response

end

#get(endpoint, params = {}) ⇒ Object

Use this method to communicate with GET endpoints

Parameters:

  • endpoint (string)

    , e.g. GET /customer

  • params (hash) (defaults to: {})

    , a list of GET parameters to be included in the request

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/sep6_client/client.rb', line 38

def get(endpoint, params = {})

  path = build_connect_url(endpoint) + '?' +  URI.encode_www_form(params)
  headers = build_headers(endpoint, 'GET', params)

  log "GET " + path
  log headers.to_s

  begin
    response = RestClient::Request.execute(method: :get, url: path, headers: headers, timeout: 180)
  rescue RestClient::ExceptionWithResponse => e
    log e.http_code.to_s + " " + e.response.to_s
    return e.response
  end

  log response.code.to_s + " " + response.to_s

  response

end

#post(endpoint, params = {}) ⇒ Object

Use this method to communicate with POST endpoints

Parameters:

  • endpoint (string)

    , e.g. POST /checkout/hosted

  • params (hash) (defaults to: {})

    , a list of GET parameters to be included in the request

Returns:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/sep6_client/client.rb', line 63

def post(endpoint, params = {})

  path = build_connect_url(endpoint)
  headers = build_headers(endpoint, 'POST', params)

  log "POST " + path + " " + params.to_s
  log headers.to_s

  begin
    response = RestClient::Request.execute(method: :post, url: path, payload: params.to_json, headers: headers, timeout: 180)
  rescue RestClient::ExceptionWithResponse => e
    log e.http_code.to_s + " " + e.response.to_s
    return e.response
  end

  log response.code.to_s + " " + response.to_s

  response

end

#put(endpoint, params = {}) ⇒ Object

Use this method to communicate with PUT endpoints

Parameters:

  • endpoint (string)

    , e.g. PUT /customer

  • params (hash) (defaults to: {})

    , a list of GET parameters to be included in the request

Returns:



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/sep6_client/client.rb', line 88

def put(endpoint, params = {})

  path = build_connect_url(endpoint)
  headers = build_headers(endpoint, 'PUT', params)

  log "PUT " + path + " " + params.to_s
  log headers.to_s

  begin
    response = RestClient::Request.execute(method: :put, url: path, payload: params.to_json, headers: headers, timeout: 180)
  rescue RestClient::ExceptionWithResponse => e
    log e.http_code.to_s + " " + e.response.to_s
    return e.response
  end

  log response.code.to_s + " " + response.to_s

  response

end