class Cortex::Client

Attributes

access_token[RW]
auth_method[RW]
base_url[RW]
content_items[R]
posts[R]
users[R]
webpages[R]

Public Class Methods

new(hasharg) click to toggle source
# File lib/cortex/client.rb, line 23
def initialize(hasharg)
  @base_url = hasharg[:base_url] || 'http://cortex.dev/api/v1'
  if hasharg.has_key? :access_token
    @access_token = hasharg[:access_token]
  else
    @key = hasharg[:key]
    @secret = hasharg[:secret]
    @scopes ||= hasharg[:scopes]
    @access_token = get_cc_token
  end
  @posts = Cortex::Posts.new(self)
  @users = Cortex::Users.new(self)
  @webpages = Cortex::Webpages.new(self)
  @content_items = Cortex::ContentItems.new(self)
end

Public Instance Methods

get_cc_token() click to toggle source
# File lib/cortex/client.rb, line 39
def get_cc_token
  begin
    client = OAuth2::Client.new(@key, @secret, site: @base_url)
    client.client_credentials.get_token({scope: @scopes})
  rescue Faraday::ConnectionFailed
    raise Cortex::Exceptions::ConnectionFailed.new(base_url: @base_url)
  end
end