module Lvmama::Request
Defines HTTP request methods
Public Instance Methods
delete(path, options={}, raw=false)
click to toggle source
Perform an HTTP DELETE request
# File lib/lvmama-api/request.rb, line 22 def delete(path, options={}, raw=false) request(:get, path, options, raw) end
get(path, options={}, raw=false)
click to toggle source
Perform an HTTP GET request
# File lib/lvmama-api/request.rb, line 7 def get(path, options={}, raw=false) request(:get, path, options, raw) end
post(path, options={}, raw=false)
click to toggle source
Perform an HTTP POST request
# File lib/lvmama-api/request.rb, line 12 def post(path, options={}, raw=false) request(:get, path, options, raw) end
put(path, options={}, raw=false)
click to toggle source
Perform an HTTP PUT request
# File lib/lvmama-api/request.rb, line 17 def put(path, options={}, raw=false) request(:get, path, options, raw) end
Private Instance Methods
generate_sign(timestamp, secret)
click to toggle source
# File lib/lvmama-api/request.rb, line 51 def generate_sign timestamp, secret sign = secret + timestamp + secret md5 = Digest::MD5.new md5 << sign md5.hexdigest end
request(method, path, options, raw=false)
click to toggle source
Perform an HTTP request
# File lib/lvmama-api/request.rb, line 29 def request(method, path, options, raw=false) response = connection(raw).send(method) do |request| timestamp = Time.now.getutc.to_i sign = generate_sign timestamp.to_s, client_secret options[:appKey] = client_id options[:messageFormat] = format options[:timestamp] = timestamp options[:sign] = sign case method when :get, :delete request.url(URI.encode(path), options) when :post, :put request.path = URI.encode(path) request.body = options unless options.empty? end end raw ? response : response.body end