class MT::DataAPI::Client

Movable Type Data API client for Ruby.

Constants

VERSION

Attributes

access_token[RW]

Public Class Methods

new(opts) click to toggle source
# File lib/mt/data_api/client.rb, line 12
def initialize(opts)
  opts_sym = opts.symbolize_keys
  unless opts_sym.key?(:client_id)
    opts_sym[:client_id] = default_client_id
  end
  @access_token = opts_sym.delete(:access_token)
  @endpoint_manager = EndpointManager.new(opts_sym)
end

Public Instance Methods

call(id, args = {}) { |res| ... } click to toggle source
# File lib/mt/data_api/client.rb, line 21
def call(id, args = {})
  id = id.to_s
  endpoint = @endpoint_manager.find_endpoint(id)
  return nil unless endpoint
  res = endpoint.call(@access_token, args)
  @access_token = res['accessToken'] if id == 'authenticate'
  @endpoint_manager.endpoints = res['items'] if id == 'list_endpoints'
  block_given? ? yield(res) : res
end
endpoints() click to toggle source
# File lib/mt/data_api/client.rb, line 31
def endpoints
  @endpoint_manager.endpoints
end

Private Instance Methods

default_client_id() click to toggle source
# File lib/mt/data_api/client.rb, line 37
def default_client_id
  'mt-data_api-client version ' + VERSION
end