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.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



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

def access_token
  @access_token
end

#auth_methodObject

Returns the value of attribute auth_method.



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

def auth_method
  @auth_method
end

#base_urlObject

Returns the value of attribute base_url.



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

def base_url
  @base_url
end

#content_itemsObject (readonly)

Returns the value of attribute content_items.



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

def content_items
  @content_items
end

#postsObject (readonly)

Returns the value of attribute posts.



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

def posts
  @posts
end

#usersObject (readonly)

Returns the value of attribute users.



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

def users
  @users
end

#webpagesObject (readonly)

Returns the value of attribute webpages.



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

def webpages
  @webpages
end

Instance Method Details

#get_cc_tokenObject



39
40
41
42
43
44
45
46
# 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