Class: DiandianOAuth::API::Interface::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/diandian_oauth/api/interface.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.param(name, options = {}) ⇒ Object



114
115
116
# File 'lib/diandian_oauth/api/interface.rb', line 114

def param name, options = {}
  params[name.to_sym] = Param.new( name.to_s, options)
end

.paramsObject



121
122
123
# File 'lib/diandian_oauth/api/interface.rb', line 121

def params
  @params ||= {}
end

.verb(verb = nil) ⇒ Object



117
118
119
120
# File 'lib/diandian_oauth/api/interface.rb', line 117

def verb verb=nil
  @verb = verb if verb
  @verb ||= 'get'
end

Instance Method Details

#apply(access_token, params, &block) ⇒ Object

Raises:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/diandian_oauth/api/interface.rb', line 76

def apply access_token, params, &block
  raise TokenExpiredError if access_token.expired?
  params = Params.new( params || {})
  action = case request_verb
  when /get/ then :get
  when /post/ then :post
  when /put/ then :put
  when /delete/ then :delete
  else raise "unrecognized verb '#{request_verb}'"
  end # case
  options = {
    :body => extract_params(params).to_a,
    :raise_errors => false,
    :parse => :json
  }
  request_url = self.request_url(params)
  if DiandianOAuth.logger.debug?
    DiandianOAuth.logger.debug("request with action:'#{action}', request_url:'#{request_url}', options:'#{options}'")
  end
  DiandianOAuth::Response.from_response access_token.request( action, request_url, options, &block)
end

#request_url(params = {}) ⇒ Object



72
73
74
# File 'lib/diandian_oauth/api/interface.rb', line 72

def request_url params = {}
  raise 'subclasses must implement this method'
end