Class: Mitake::API::Base Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mitake/api/base.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

Direct Known Subclasses

Get, Post

Instance Method Summary collapse

Constructor Details

#initialize(path, params = {}) ⇒ Base

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Base.

Parameters:

  • path (String)

    the api endpoint

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

    the request body

Since:

  • 0.1.0



16
17
18
19
# File 'lib/mitake/api/base.rb', line 16

def initialize(path, params = {})
  @path = path
  @params = params
end

Instance Method Details

#executeNet::HTTPResponse

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Execute HTTP Request

Returns:

  • (Net::HTTPResponse)

    the request result

Since:

  • 0.1.0



33
34
35
36
37
# File 'lib/mitake/api/base.rb', line 33

def execute
  Net::HTTP.start(uri.host, uri.port, use_ssl: ssl?) do |http|
    http.request request
  end
end

#paramsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the request params

Returns:

  • (Hash)

    the query params

Since:

  • 0.1.0



61
62
63
64
65
66
# File 'lib/mitake/api/base.rb', line 61

def params
  @params.merge(
    username: Mitake.credential.username,
    password: Mitake.credential.password
  )
end

#requestObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



23
24
25
# File 'lib/mitake/api/base.rb', line 23

def request
  raise NotImplementedError, 'Request not defined!'
end

#ssl?TrueClass|FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns is the SSL request.

Returns:

  • (TrueClass|FalseClass)

    is the SSL request

Since:

  • 0.1.0



51
52
53
# File 'lib/mitake/api/base.rb', line 51

def ssl?
  @uri.scheme == 'https'
end

#uriURI

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the request URI.

Returns:

  • (URI)

    the request URI

Since:

  • 0.1.0



43
44
45
# File 'lib/mitake/api/base.rb', line 43

def uri
  @uri ||= URI("#{Mitake.credential.server}#{@path}")
end