class Blockmason::Link::Project

The entry-point for most apps to integrate with a Blockmason Link project.

Public Class Methods

new(base_url: ::Blockmason::Link::Provider.default_url, client_id:, client_secret:) click to toggle source

Initialize a Project with your Link project's client_id and client_secret. Optionally, you can provide an alternative base_url here. For example, if mocking server responses for an integration test suite, or if using a Link-compatible API provider.

# File lib/blockmason/link/project.rb, line 13
def initialize(base_url: ::Blockmason::Link::Provider.default_url, client_id:, client_secret:)
  @base_url = base_url
  @client_id = client_id
  @client_secret = client_secret
end

Public Instance Methods

get(path, inputs = {}) click to toggle source

Performs a GET request against a Link project's API at the given path and with the given optional inputs. Returns the outputs returned for the API call.

# File lib/blockmason/link/project.rb, line 23
def get(path, inputs = {})
  session.get(path, inputs)
end
post(path, inputs = {}) click to toggle source

Performs a POST request against a Link project's API at the given path and with the given optional inputs. Returns the outputs returned for the API call.

# File lib/blockmason/link/project.rb, line 31
def post(path, inputs = {})
  session.post(path, inputs)
end

Private Instance Methods

connection() click to toggle source
# File lib/blockmason/link/project.rb, line 36
def connection
  @connection ||= connection!
end
connection!() click to toggle source
# File lib/blockmason/link/project.rb, line 48
def connection!
  @connection = provider.connect!(@base_url)
  @connection
end
provider() click to toggle source
# File lib/blockmason/link/project.rb, line 40
def provider
  @provider ||= provider!
end
provider!() click to toggle source
# File lib/blockmason/link/project.rb, line 53
def provider!
  @provider = ::Blockmason::Link::Provider.new
  @provider
end
session() click to toggle source
# File lib/blockmason/link/project.rb, line 44
def session
  @session ||= session!
end
session!() click to toggle source
# File lib/blockmason/link/project.rb, line 58
def session!
  @session = connection.authenticate!(client_id: @client_id, client_secret: @client_secret)
  @session
end