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, #delete!, #get, #parse_response, #post, #put, #save

Methods included from Connection

#connection

Constructor Details

#initialize(hasharg) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cortex/client.rb', line 18

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]
    @access_token = get_cc_token
  end
  @posts = Cortex::Posts.new(self)
  @users = Cortex::Users.new(self)
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



11
12
13
# File 'lib/cortex/client.rb', line 11

def access_token
  @access_token
end

#auth_methodObject

Returns the value of attribute auth_method.



11
12
13
# File 'lib/cortex/client.rb', line 11

def auth_method
  @auth_method
end

#base_urlObject

Returns the value of attribute base_url.



11
12
13
# File 'lib/cortex/client.rb', line 11

def base_url
  @base_url
end

#postsObject (readonly)

Returns the value of attribute posts.



10
11
12
# File 'lib/cortex/client.rb', line 10

def posts
  @posts
end

#usersObject (readonly)

Returns the value of attribute users.



10
11
12
# File 'lib/cortex/client.rb', line 10

def users
  @users
end

Instance Method Details

#get_cc_tokenObject



31
32
33
34
# File 'lib/cortex/client.rb', line 31

def get_cc_token
  client = OAuth2::Client.new(@key, @secret, site: @base_url)
  client.client_credentials.get_token
end