class Stackd::Token
Public Class Methods
new(client, attrs = {})
click to toggle source
# File lib/stackd/token.rb, line 23 def initialize client, attrs = {} self.client = client attrs.each do |key, val| public_send :"#{key}=", val if tattr? key end begin require_attr! :client, :access_token, :token_type rescue Concerns::RequireAttr::AttrNotSetError => e raise ArgumentError.new e.message end end
on_grant(&block)
click to toggle source
# File lib/stackd/token.rb, line 19 def self.on_grant &block @_on_grant_callbacks.push block end
Public Instance Methods
delete(*args)
click to toggle source
# File lib/stackd/token.rb, line 65 def delete *args url_args = reject_body_arg *args body_arg = get_body_arg *args content_type = content_type_for body_arg Util::HTTP.delete self, get_url(*url_args), body_arg, content_type end
get(*args)
click to toggle source
# File lib/stackd/token.rb, line 37 def get *args Util::HTTP.get self, get_url(*args) end
patch(*args)
click to toggle source
# File lib/stackd/token.rb, line 57 def patch *args url_args = reject_body_arg *args body_arg = get_body_arg *args content_type = content_type_for body_arg Util::HTTP.patch self, get_url(*url_args), body_arg, content_type end
post(*args)
click to toggle source
# File lib/stackd/token.rb, line 41 def post *args url_args = reject_body_arg *args body_arg = get_body_arg *args content_type = content_type_for body_arg Util::HTTP.post self, get_url(*url_args), body_arg, content_type end
put(*args)
click to toggle source
# File lib/stackd/token.rb, line 49 def put *args url_args = reject_body_arg *args body_arg = get_body_arg *args content_type = content_type_for body_arg Util::HTTP.put self, get_url(*url_args), body_arg, content_type end
Private Instance Methods
content_type_for(body_arg)
click to toggle source
# File lib/stackd/token.rb, line 99 def content_type_for body_arg :json unless body_arg.nil? end
get_body_arg(*args)
click to toggle source
# File lib/stackd/token.rb, line 95 def get_body_arg *args args.last if args.last.is_a? Hash end
get_url(*args)
click to toggle source
# File lib/stackd/token.rb, line 75 def get_url *args args.inject Stackd.config.api_url do |url, part| if part.is_a? Hash "#{url}?#{part.to_query}" else part = part.to_s if part.index(Stackd.config.api_url) == 0 part elsif part.index('/') == 0 "#{url}#{part}" else "#{url}/#{part}" end end end end
reject_body_arg(*args)
click to toggle source
# File lib/stackd/token.rb, line 91 def reject_body_arg *args args.reject {|a| a.is_a? Hash } end