Class: Cortex::Client
- Inherits:
-
Object
- Object
- Cortex::Client
- Includes:
- Connection, Request
- Defined in:
- lib/cortex/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#auth_method ⇒ Object
Returns the value of attribute auth_method.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#content_items ⇒ Object
readonly
Returns the value of attribute content_items.
-
#posts ⇒ Object
readonly
Returns the value of attribute posts.
-
#users ⇒ Object
readonly
Returns the value of attribute users.
-
#webpages ⇒ Object
readonly
Returns the value of attribute webpages.
Instance Method Summary collapse
- #get_cc_token ⇒ Object
-
#initialize(hasharg) ⇒ Client
constructor
A new instance of Client.
Methods included from Request
#delete, #get, #parse_response, #post, #put, #save
Methods included from 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_token ⇒ Object
Returns the value of attribute access_token.
15 16 17 |
# File 'lib/cortex/client.rb', line 15 def access_token @access_token end |
#auth_method ⇒ Object
Returns the value of attribute auth_method.
15 16 17 |
# File 'lib/cortex/client.rb', line 15 def auth_method @auth_method end |
#base_url ⇒ Object
Returns the value of attribute base_url.
15 16 17 |
# File 'lib/cortex/client.rb', line 15 def base_url @base_url end |
#content_items ⇒ Object (readonly)
Returns the value of attribute content_items.
14 15 16 |
# File 'lib/cortex/client.rb', line 14 def content_items @content_items end |
#posts ⇒ Object (readonly)
Returns the value of attribute posts.
14 15 16 |
# File 'lib/cortex/client.rb', line 14 def posts @posts end |
#users ⇒ Object (readonly)
Returns the value of attribute users.
14 15 16 |
# File 'lib/cortex/client.rb', line 14 def users @users end |
#webpages ⇒ Object (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_token ⇒ Object
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 |