class SageoneSdk::Client

Client

Public Class Methods

new(options = {}) click to toggle source
# File lib/sageone_sdk/client.rb, line 59
def initialize(options = {})
  SageoneSdk::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", options[key] || SageoneSdk.instance_variable_get(:"@#{key}"))
  end
end

Public Instance Methods

agent() click to toggle source
# File lib/sageone_sdk/client.rb, line 96
def agent
  @agent ||= Faraday.new(api_endpoint, faraday_options) do |builder|
    builder.request :url_encoded
    builder.headers['Accept'] = default_media_type
    builder.headers['Content-Type'] = "application/x-www-form-urlencoded"
    builder.headers['User-Agent'] = user_agent
    if token_authenticated?
      builder.authorization 'Bearer', @access_token
    end
    builder.use SageoneSdk::Middleware::Signature, access_token, signing_secret
    builder.use SageoneSdk::Middleware::SDataParser
    builder.adapter Faraday.default_adapter
  end
end
delete(path, data={}) click to toggle source
# File lib/sageone_sdk/client.rb, line 86
def delete(path, data={})
  request(:delete, path, data)
end
get(path, data={}) click to toggle source
# File lib/sageone_sdk/client.rb, line 74
def get(path, data={})
  request(:get, path, data)
end
last_response() click to toggle source
# File lib/sageone_sdk/client.rb, line 65
def last_response
  @last_response if defined? @last_response
end
paginate(resource, options = {}) click to toggle source
# File lib/sageone_sdk/client.rb, line 69
def paginate(resource, options = {})
  data = get(resource, options)
  data
end
post(path, data={}) click to toggle source
# File lib/sageone_sdk/client.rb, line 78
def post(path, data={})
  request(:post, path, data)
end
put(path, data={}) click to toggle source
# File lib/sageone_sdk/client.rb, line 82
def put(path, data={})
  request(:put, path, data)
end
request(method, path, data, options = {}) click to toggle source
# File lib/sageone_sdk/client.rb, line 90
def request(method, path, data, options = {})
  path = File.join("accounts", "v1", path)
  @last_response = response = agent.public_send(method, URI::Parser.new.escape(path.to_s), data, options)
  response.body
end

Private Instance Methods

faraday_options() click to toggle source
# File lib/sageone_sdk/client.rb, line 113
def faraday_options
  {}
end