class PlanningCenter::Client

Constants

SITE

Attributes

access_token[RW]
access_token_secret[RW]
consumer_key[RW]
consumer_secret[RW]

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/planning_center/client.rb, line 18
def initialize
  yield(self) if block_given?
end

Public Instance Methods

get(path, headers = {}) click to toggle source
# File lib/planning_center/client.rb, line 26
def get(path, headers = {})
  request(:get, path, headers)
end
organization() click to toggle source
# File lib/planning_center/client.rb, line 22
def organization
  Organization.find(self)
end
post(path, body, headers = {}) click to toggle source
# File lib/planning_center/client.rb, line 30
def post(path, body, headers = {})
  request_with_body(:post, path, body, headers)
end
put(path, body, headers = {}) click to toggle source
# File lib/planning_center/client.rb, line 34
def put(path, body, headers = {})
  request_with_body(:put, path, body, headers)
end

Private Instance Methods

consumer() click to toggle source
# File lib/planning_center/client.rb, line 55
def consumer
  @consumer ||= OAuth::Consumer.new(
    consumer_key,
    consumer_secret,
    site: SITE,
    signature_method: 'plaintext'
  )
end
default_headers() click to toggle source
# File lib/planning_center/client.rb, line 40
def default_headers
  {
    'content-type' => 'application/json',
    'accept' => 'application/json'
  }
end
oauth() click to toggle source
# File lib/planning_center/client.rb, line 47
def oauth
  @oauth ||= OAuth::AccessToken.new(
    consumer,
    access_token,
    access_token_secret
  )
end
parse_response(response) click to toggle source
# File lib/planning_center/client.rb, line 74
def parse_response(response)
  JSON.parse(response.body)
rescue JSON::ParserError
  raise(
    APIError,
    'Invalid response from API. ' \
    "Code: #{response.code}, " \
    "Body: #{response.body.inspect} "
  )
end
request(type, path, headers = {}) click to toggle source
# File lib/planning_center/client.rb, line 64
def request(type, path, headers = {})
  response = oauth.request(type, path, default_headers.merge(headers))
  parse_response(response)
end
request_with_body(type, path, body, headers = {}) click to toggle source
# File lib/planning_center/client.rb, line 69
def request_with_body(type, path, body, headers = {})
  response = oauth.request(type, path, body, default_headers.merge(headers))
  parse_response(response)
end