Class: TijuanaClient::Client
- Inherits:
-
Vertebrae::API
- Object
- Vertebrae::API
- TijuanaClient::Client
- Defined in:
- lib/tijuana_client/client.rb
Instance Method Summary collapse
- #default_options ⇒ Object
- #post_json_request(path, params) ⇒ Object
-
#request(method, path, params, options) ⇒ Object
:nodoc:.
- #setup ⇒ Object
- #user ⇒ Object
Instance Method Details
#default_options ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/tijuana_client/client.rb', line 15 def { user_agent: 'TijuanaClient', prefix: '', content_type: 'application/x-www-form-urlencoded' } end |
#post_json_request(path, params) ⇒ Object
9 10 11 12 13 |
# File 'lib/tijuana_client/client.rb', line 9 def post_json_request(path, params) p = {} p['data'] = params.to_json post_request(path, p) end |
#request(method, path, params, options) ⇒ Object
:nodoc:
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tijuana_client/client.rb', line 23 def request(method, path, params, ) # :nodoc: raise ArgumentError, "unknown http method: #{method}" unless ::Vertebrae::Request::METHODS.include?(method) path = "#{connection.configuration.prefix}/#{path}" ::Vertebrae::Base.logger.debug "EXECUTED: #{method} - #{path} with #{params} and #{}" connection.connection.send(method) do |request| case method.to_sym when *(::Vertebrae::Request::METHODS - ::Vertebrae::Request::METHODS_WITH_BODIES) request.body = params.delete('data') if params.key?('data') request.url(path, params) when *::Vertebrae::Request::METHODS_WITH_BODIES request.path = path request.body = extract_data_from_params(params) unless params.empty? end end end |
#setup ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tijuana_client/client.rb', line 42 def setup connection.stack do |builder| builder.use Faraday::Request::Multipart builder.use Faraday::Request::UrlEncoded if connection.configuration.authenticated? builder.use Faraday::Request::BasicAuthentication, connection.configuration.username, connection.configuration.password end builder.use Faraday::Response::Logger if ENV['DEBUG'] builder.use TijuanaClient::ErrorMiddleware builder.adapter connection.configuration.adapter end end |
#user ⇒ Object
5 6 7 |
# File 'lib/tijuana_client/client.rb', line 5 def user @user ||= TijuanaClient::User.new(client: self) end |