Class: Sonar::Client
- Inherits:
-
Object
- Object
- Sonar::Client
- Extended by:
- Forwardable
- Includes:
- Certificate, Registration, Request, Search, User
- Defined in:
- lib/sonar/client.rb
Constant Summary
Constants included from Search
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#email ⇒ Object
Returns the value of attribute email.
Instance Method Summary collapse
-
#connection ⇒ Faraday::Connection
Create a Faraday::Connection object.
-
#get_endpoint(type, params = {}) ⇒ Object
Generic GET of Sonar Objects.
-
#get_search_endpoint(type, params = {}) ⇒ Object
Generic GET of Sonar search Objects.
-
#initialize(options = {}) ⇒ Client
constructor
Create a new Sonar::Client object.
-
#post_to_sonar(type, params = {}) ⇒ Object
Generic POST to Sonar.
Methods included from Registration
Methods included from User
Methods included from Search
Methods included from Certificate
Methods included from Request
#extract_params, #get, #post, #put, #request
Constructor Details
#initialize(options = {}) ⇒ Client
Create a new Sonar::Client object
28 29 30 31 32 33 |
# File 'lib/sonar/client.rb', line 28 def initialize( = {}) @api_url = .fetch(:api_url, default_api_url) @api_version = .fetch(:api_version, default_api_version ) @access_token = .fetch(:access_token, default_access_token) @email = .fetch(:email, default_email) end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
22 23 24 |
# File 'lib/sonar/client.rb', line 22 def access_token @access_token end |
#api_url ⇒ Object
Returns the value of attribute api_url.
22 23 24 |
# File 'lib/sonar/client.rb', line 22 def api_url @api_url end |
#api_version ⇒ Object
Returns the value of attribute api_version.
22 23 24 |
# File 'lib/sonar/client.rb', line 22 def api_version @api_version end |
#email ⇒ Object
Returns the value of attribute email.
22 23 24 |
# File 'lib/sonar/client.rb', line 22 def email @email end |
Instance Method Details
#connection ⇒ Faraday::Connection
Create a Faraday::Connection object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sonar/client.rb', line 39 def connection params = {} @conn = Faraday.new(url: api_url, params: params, headers: default_headers, ssl: { verify: true }) do |faraday| faraday.use FaradayMiddleware::Mashify faraday.use FaradayMiddleware::ParseJson, content_type: /\bjson$/ faraday.use FaradayMiddleware::FollowRedirects faraday.adapter Faraday.default_adapter end @conn.headers['X-Sonar-Token'] = access_token @conn.headers['X-Sonar-Email'] = email @conn end |
#get_endpoint(type, params = {}) ⇒ Object
Generic GET of Sonar Objects
65 66 67 68 |
# File 'lib/sonar/client.rb', line 65 def get_endpoint(type, params = {}) url = "/api/#{api_version}/#{type}" get(url, params) end |
#get_search_endpoint(type, params = {}) ⇒ Object
Generic GET of Sonar search Objects
54 55 56 57 58 59 60 61 |
# File 'lib/sonar/client.rb', line 54 def get_search_endpoint(type, params = {}) url = "/api/#{api_version}/search/#{type}" if params[:limit] RequestIterator.new(url, connection, params) else get(url, params) end end |
#post_to_sonar(type, params = {}) ⇒ Object
Generic POST to Sonar
72 73 74 75 |
# File 'lib/sonar/client.rb', line 72 def post_to_sonar(type, params = {}) url = "/api/#{api_version}/#{type}" post(url, params) end |