Class: FancyHands::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.



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

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

Instance Method Details

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



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

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



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

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



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

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

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



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

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