Class: MinxingRubySdk::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/minxing_ruby_sdk/account.rb

Direct Known Subclasses

Ocu::OcuAccount

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



4
5
6
# File 'lib/minxing_ruby_sdk/account.rb', line 4

def connection
  @connection
end

Instance Method Details

#apiForResponse(method, url, withTokenHeader, headers, params) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/minxing_ruby_sdk/account.rb', line 23

def apiForResponse(method, url, withTokenHeader, headers, params)
  method = 'get' if method.empty?
  method = method.downcase
  if withTokenHeader
    @connection.tokenType = "Bearer" if @connection.tokenType.empty?

    headers['Authorization'] =  @connection.tokenType + " " + @connection.token
    # headers["API-RemoteIP"] =  ipaddr.getHostAddress()
    # client.getHostConfiguration().getParams()
    #     .setParameter("http.default-headers", headers);
  end
  response = @connection.connection.send(method) do |req|
    LOGGER.debug(url)
    LOGGER.debug(headers)
    LOGGER.debug(params)

    req.url url
    req.headers = headers
    req.body = params
  end

  response.body

end

#delete(url, withTokenHeader = true, headers, params) ⇒ Object



18
19
20
# File 'lib/minxing_ruby_sdk/account.rb', line 18

def delete(url, withTokenHeader=true, headers, params)
  apiForResponse('delete', url, withTokenHeader, headers, params)
end

#get(url, withTokenHeader = true, headers, params) ⇒ Object



6
7
8
# File 'lib/minxing_ruby_sdk/account.rb', line 6

def get(url, withTokenHeader=true, headers, params)
  apiForResponse('get', url, withTokenHeader, headers, params)
end

#post(url, withTokenHeader = true, headers, params) ⇒ Object



10
11
12
# File 'lib/minxing_ruby_sdk/account.rb', line 10

def post(url, withTokenHeader=true, headers, params)
  apiForResponse('post', url, withTokenHeader, headers, params)
end

#put(url, withTokenHeader = true, headers, params) ⇒ Object



14
15
16
# File 'lib/minxing_ruby_sdk/account.rb', line 14

def put(url, withTokenHeader=true, headers, params)
  apiForResponse('put', url, withTokenHeader, headers, params)
end