Class: MT::DataAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mt/data_api/client.rb,
lib/mt/data_api/client/version.rb,
lib/mt/data_api/client/endpoint.rb,
lib/mt/data_api/client/api_request.rb,
lib/mt/data_api/client/endpoint_manager.rb

Overview

Movable Type Data API client for Ruby.

Defined Under Namespace

Classes: APIRequest, Endpoint, EndpointManager

Constant Summary collapse

VERSION =
'0.0.5'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
19
# 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

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



10
11
12
# File 'lib/mt/data_api/client.rb', line 10

def access_token
  @access_token
end

Instance Method Details

#call(id, args = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
# 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

#endpointsObject



31
32
33
# File 'lib/mt/data_api/client.rb', line 31

def endpoints
  @endpoint_manager.endpoints
end