Module: Tumblr::Request

Included in:
Client
Defined in:
lib/tumblr/request.rb,
lib/tumblr/request/oauth.rb

Defined Under Namespace

Classes: TumblrOAuth

Instance Method Summary collapse

Instance Method Details

#get(path, params = {}) ⇒ Object

Performs a get request



7
8
9
10
11
12
13
14
# File 'lib/tumblr/request.rb', line 7

def get(path, params={})
  response = connection.get do |req|
    req.url path 
    req.params = params
  end
  #Check for errors and encapsulate
  respond(response)
end

#post(path, params = {}) ⇒ Object

Performs post request



17
18
19
20
21
22
23
24
# File 'lib/tumblr/request.rb', line 17

def post(path, params={})
  response = connection.post do |req|
    req.url path
    req.body = params unless params.empty?
  end
  #Check for errors and encapsulate
  respond(response)
end

#respond(response) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/tumblr/request.rb', line 26

def respond(response)
  if [201, 200].include?(response.status)
    response.body['response']
  else
    response.body['meta']
  end
end