Class: TokyoApi::Client
- Inherits:
-
Vertebrae::API
- Object
- Vertebrae::API
- TokyoApi::Client
- Defined in:
- lib/tokyo_api/client.rb
Instance Method Summary collapse
- #actionkit ⇒ Object (also: #action_kit)
- #campact ⇒ Object
- #default_options ⇒ Object
- #expire ⇒ Object
- #external_image ⇒ Object
- #identity ⇒ Object
-
#request(method, path, params, options) ⇒ Object
:nodoc:.
- #setup ⇒ Object
Instance Method Details
#actionkit ⇒ Object Also known as: action_kit
5 6 7 |
# File 'lib/tokyo_api/client.rb', line 5 def actionkit @actionkit ||= TokyoApi::Actionkit.new(client: self) end |
#campact ⇒ Object
11 12 13 |
# File 'lib/tokyo_api/client.rb', line 11 def campact @campact ||= TokyoApi::Campact.new(client: self) end |
#default_options ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tokyo_api/client.rb', line 27 def opts = { user_agent: 'TokyoApi Gem', prefix: '', content_type: 'application/json' } if .key?(:timeout) opts[:connection_options] = { request: { timeout: [:timeout] } } end opts end |
#expire ⇒ Object
23 24 25 |
# File 'lib/tokyo_api/client.rb', line 23 def expire @expire ||= TokyoApi::Expire.new(client: self) end |
#external_image ⇒ Object
19 20 21 |
# File 'lib/tokyo_api/client.rb', line 19 def external_image @external_image ||= TokyoApi::ExternalImage.new(client: self) end |
#identity ⇒ Object
15 16 17 |
# File 'lib/tokyo_api/client.rb', line 15 def identity @identity ||= TokyoApi::Identity.new(client: self) end |
#request(method, path, params, options) ⇒ Object
:nodoc:
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tokyo_api/client.rb', line 41 def request(method, path, params, ) # :nodoc: raise ArgumentError, "unknown http method: #{method}" unless ::Vertebrae::Request::METHODS.include?(method) path = "#{connection.configuration.prefix}/#{path}" unless connection.configuration.prefix.blank? ::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.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
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/tokyo_api/client.rb', line 59 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 FaradayMiddleware::Mashify builder.use FaradayMiddleware::ParseJson builder.use Vertebrae::Response::RaiseError builder.adapter connection.configuration.adapter end end |