Module: Mitake::API::ClassMethods Private

Defined in:
lib/mitake/api.rb

Overview

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

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#execute(params = {}, &_block) {|items| ... } ⇒ Mitake::API

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 API

Parameters:

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

    the API params

  • _block (Proc)

    the customize process

Yields:

  • (items)

Returns:

Raises:

Since:

  • 0.1.0



74
75
76
77
78
79
80
81
82
# File 'lib/mitake/api.rb', line 74

def execute(params = {}, &_block)
  res = request(params)
  raise Mitake::API::Error, res.code unless res.is_a?(Net::HTTPOK)

  items = Parser.new(res).parse.map { |item| rename_attribute(item) }
  return items.map { |item| new(item) } unless block_given?

  yield items
end

#map(from, to) ⇒ Object

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.

Set response field mapping

Parameters:

  • from (String)

    the response field

  • to (String)

    the target field

Since:

  • 0.1.0



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

def map(from, to)
  @mapping ||= {}
  @mapping[from.to_s] = to.to_s
end

#method(method = nil) ⇒ String

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.

Set/Get the api method

Parameters:

  • method (String) (defaults to: nil)

    the api request method

Returns:

  • (String)

    if method not given, return previous value

Since:

  • 0.1.0



48
49
50
51
52
# File 'lib/mitake/api.rb', line 48

def method(method = nil)
  return @method if method.nil?

  @method = method.to_s.capitalize
end

#path(path = nil) ⇒ String

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.

Set/Get the api path

Parameters:

  • path (String) (defaults to: nil)

    the api endpoint path

Returns:

  • (String)

    if path not given, return previous value

Since:

  • 0.1.0



35
36
37
38
39
# File 'lib/mitake/api.rb', line 35

def path(path = nil)
  return @path if path.nil?

  @path = path
end