class Naver::Searchad::Api::Core::BaseService
Attributes
base_path[R]
client_options[RW]
request_options[RW]
url[R]
Public Class Methods
new(url, base_path = '')
click to toggle source
# File lib/naver/searchad/api/core/base_service.rb, line 23 def initialize(url, base_path = '') @url = url @base_path = base_path @request_options = RequestOptions.default.dup @client_options = ClientOptions.default.dup end
Public Instance Methods
client()
click to toggle source
# File lib/naver/searchad/api/core/base_service.rb, line 38 def client @client ||= new_client end
Protected Instance Methods
apply_command_defaults(command)
click to toggle source
# File lib/naver/searchad/api/core/base_service.rb, line 65 def apply_command_defaults(command) # To be implemented by subclasses end
execute_command(command, &block)
click to toggle source
# File lib/naver/searchad/api/core/base_service.rb, line 61 def execute_command(command, &block) command.execute(client, &block) end
make_command(method, path, options = {})
click to toggle source
# File lib/naver/searchad/api/core/base_service.rb, line 44 def make_command(method, path, options = {}) template = Addressable::Template.new(url + base_path + path) command = ApiCommand.new(method, template) command.decode_snake_case = options.fetch(:decode_snake_case, true) if options command.options = request_options.merge(options) apply_command_defaults(command) command end
make_download_command(method, path, options = {})
click to toggle source
# File lib/naver/searchad/api/core/base_service.rb, line 53 def make_download_command(method, path, options = {}) template = Addressable::Template.new(url + base_path + path) command = DownloadCommand.new(method, template) command.options = request_options.merge(options) apply_command_defaults(command) command end
validates_presence_of(fields, object)
click to toggle source
# File lib/naver/searchad/api/core/base_service.rb, line 69 def validates_presence_of(fields, object) fields.each do |key| unless object.key?(key) raise MissingRequiredAttributeError.new( "Require #{key} attribute in object") end end end
Private Instance Methods
new_client()
click to toggle source
# File lib/naver/searchad/api/core/base_service.rb, line 80 def new_client HTTPClient.new.tap do |client| client.transparent_gzip_decompression = true client.proxy = client_options.proxy_url if client_options.proxy_url client.connect_timeout = client_options.open_timeout_sec if client_options.open_timeout_sec client.receive_timeout = client_options.read_timeout_sec if client_options.read_timeout_sec client.send_timeout = client_options.send_timeout_sec if client_options.send_timeout_sec client.follow_redirect_count = 5 client.default_header = { 'User-Agent' => user_agent } client.debug_dev = logger if client_options.log_http_requests # Honor openssl configuration client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_PEER end end
user_agent()
click to toggle source
# File lib/naver/searchad/api/core/base_service.rb, line 95 def user_agent "#{client_options.application_name}/#{client_options.application_version} "\ "naver-searchad-api/#{Naver::Searchad::Api::VERSION} "\ "#{Naver::Searchad::Api::OS_VERSION} (gzip)" end