Class: Request

Inherits:
Object
  • Object
show all
Defined in:
lib/fancyhands/v1/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, url) ⇒ Request

Returns a new instance of Request.



4
5
6
7
# File 'lib/fancyhands/v1/request.rb', line 4

def initialize(key, secret, url)
  @url = url
  @consumer = OAuth::Consumer.new(key, secret)
end

Instance Method Details

#delete(piece, data = "") ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/fancyhands/v1/request.rb', line 14

def delete(piece, data="")
  if data
    uri = Addressable::URI.new
    uri.query_values = data
    data = uri.query
  end
  full = @url + piece + "?" + data
  response = @consumer.request(:delete, full)
  return JSON.parse(response.body)
end

#get(piece, data = "") ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/fancyhands/v1/request.rb', line 31

def get(piece, data="")
  if data
    uri = Addressable::URI.new
    uri.query_values = data
    data = uri.query
  end
  full = @url + piece + "?" + data
  response = @consumer.request(:get, full)
  return JSON.parse(response.body)
end

#post(piece, data = "") ⇒ Object



9
10
11
12
# File 'lib/fancyhands/v1/request.rb', line 9

def post(piece, data="")
  response = @consumer.request(:post, @url + piece, nil, {}, data)
  return JSON.parse(response.body)
end

#put(piece, data = "") ⇒ Object



25
26
27
28
29
# File 'lib/fancyhands/v1/request.rb', line 25

def put(piece, data="")
  # {'Content-Type' => 'application/x-www-form-urlencoded'}
  response = @consumer.request(:put, @url + piece, nil, {}, data)
  return JSON.parse(response.body)
end