class Twitty::Facade
Public Class Methods
new() { |config| ... }
click to toggle source
# File lib/twitty/facade.rb, line 7 def initialize yield(config) if block_given? end
Public Instance Methods
generate_crc(crc_token)
click to toggle source
# File lib/twitty/facade.rb, line 17 def generate_crc(crc_token) hash = OpenSSL::HMAC.digest('sha256', config.consumer_secret, crc_token) Base64.encode64(hash).strip! end
override_client_tokens(access_token, access_token_secret)
click to toggle source
# File lib/twitty/facade.rb, line 22 def override_client_tokens(access_token, access_token_secret) config.access_token = access_token config.access_token_secret = access_token_secret end
Private Instance Methods
api_method(action)
click to toggle source
# File lib/twitty/facade.rb, line 58 def api_method(action) API_CONFIG[action][:method] end
api_params(action, data)
click to toggle source
# File lib/twitty/facade.rb, line 41 def api_params(action, data) build_payload(action, data) end
api_url(action, data)
click to toggle source
# File lib/twitty/facade.rb, line 53 def api_url(action, data) url_params = data.merge(env: config.environment).map { |k, v| [k, CGI.escape(v)] }.to_h "#{config.base_url}#{API_CONFIG[action][:endpoint]}" % url_params end
config()
click to toggle source
# File lib/twitty/facade.rb, line 49 def config @config ||= Twitty::Config.new end
define_actions(action, data)
click to toggle source
# File lib/twitty/facade.rb, line 29 def define_actions(action, data) validate_params(action, data) response = send_request(api_url(action, data), api_method(action), api_params(action, data)) Twitty::Response.new(response) end
send_request(url, type, params)
click to toggle source
# File lib/twitty/facade.rb, line 45 def send_request(url, type, params) Twitty::Request.new(url: url, type: type, payload: params, config: config).execute end
validate_params(action, data)
click to toggle source
# File lib/twitty/facade.rb, line 36 def validate_params(action, data) missing_params = (API_CONFIG[action][:required_params] - data.keys.map(&:to_sym)) raise Twitty::Errors::MissingParams, missing_params.join(',') unless missing_params.empty? end