Sha256: 08db21302a5a2b9dbbc6b20d98522d1b8f15551050536202a5b9e3bb125079fe
Contents?: true
Size: 1.21 KB
Versions: 5
Compression:
Stored size: 1.21 KB
Contents
require 'cortex/connection' require 'cortex/request' require 'cortex/resource' require 'cortex/posts' require 'cortex/users' require 'cortex/webpages' require 'cortex/result' require 'oauth2' require 'cortex/exceptions' module Cortex class Client attr_reader :posts, :users, :webpages attr_accessor :access_token, :base_url, :auth_method @key = '' @secret = '' @scopes = '' include Cortex::Connection include Cortex::Request def initialize(hasharg) @base_url = hasharg[:base_url] || 'https://cbcortex.com/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) end 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 end end
Version data entries
5 entries across 5 versions & 1 rubygems