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.4'.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
# File 'lib/mt/data_api/client.rb', line 12

def initialize(opts)
  opts = opts.symbolize_keys
  @access_token = opts.delete(:access_token)
  @endpoint_manager = EndpointManager.new(opts)
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



18
19
20
21
22
23
24
25
26
# File 'lib/mt/data_api/client.rb', line 18

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



28
29
30
# File 'lib/mt/data_api/client.rb', line 28

def endpoints
  @endpoint_manager.endpoints
end