class Freee::Base

Attributes

client[R]

Public Class Methods

config(client_id, secret_key, token) click to toggle source
# File lib/freee/base.rb, line 47
def self.config(client_id, secret_key, token)
  @@client_id = client_id.to_s
  @@secret_key = secret_key.to_s
  @@token = token.to_s
end
new() click to toggle source
# File lib/freee/base.rb, line 53
def initialize; end
set_env() click to toggle source
# File lib/freee/base.rb, line 41
def self.set_env
  @@client_id = ENV["FREEE_CLIENT_ID"]
  @@secret_key = ENV["FREEE_SECRET_KEY"]
  @@token = ENV["FREEE_APPLICATION_TOKEN"]
end

Public Instance Methods

get(path, type=nil) click to toggle source
# File lib/freee/base.rb, line 68
def get(path, type=nil)
  response = @client.get(path).response.env[:body]
  return Freee::Response::Type.convert(response, type)
end
post(path, type=nil, params) click to toggle source
# File lib/freee/base.rb, line 73
def post(path, type=nil, params)
  response = @client.post(path, { body: {params: params} }).response.env[:body]
rescue
  response = @client.post(path + params).response.env[:body]
ensure
  return Freee::Response::Type.convert(response, type)
end
token() click to toggle source
# File lib/freee/base.rb, line 60
def token
  @@token
end
token=(token) click to toggle source
# File lib/freee/base.rb, line 64
def token=(token)
  @@token = token
end

Private Instance Methods

create_client() click to toggle source
# File lib/freee/base.rb, line 82
def create_client
  OAuth2::Client.new(@@client_id, @@secret_key, OPTIONS) do |con|
    con.request :url_encoded
    con.request :json
    con.response :json, content_type: /\bjson$/
    con.adapter Faraday.default_adapter
  end
end