Class: Cortex::Client

Inherits:
Object
  • Object
show all
Includes:
Connection, Request
Defined in:
lib/cortex/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request

#delete, #get, #parse_response, #post, #put, #save

Methods included from Connection

#connection

Constructor Details

#initialize(hasharg) ⇒ Client

Returns a new instance of Client.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cortex/client.rb', line 22

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

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



14
15
16
# File 'lib/cortex/client.rb', line 14

def access_token
  @access_token
end

#auth_methodObject

Returns the value of attribute auth_method.



14
15
16
# File 'lib/cortex/client.rb', line 14

def auth_method
  @auth_method
end

#base_urlObject

Returns the value of attribute base_url.



14
15
16
# File 'lib/cortex/client.rb', line 14

def base_url
  @base_url
end

#postsObject (readonly)

Returns the value of attribute posts.



13
14
15
# File 'lib/cortex/client.rb', line 13

def posts
  @posts
end

#usersObject (readonly)

Returns the value of attribute users.



13
14
15
# File 'lib/cortex/client.rb', line 13

def users
  @users
end

#webpagesObject (readonly)

Returns the value of attribute webpages.



13
14
15
# File 'lib/cortex/client.rb', line 13

def webpages
  @webpages
end

Instance Method Details

#get_cc_tokenObject



37
38
39
40
41
42
43
44
# File 'lib/cortex/client.rb', line 37

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