Class: InoreaderApi::Helper

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/inoreader/api/helper.rb

Constant Summary collapse

@@return_httparty_response =

option: use httparty respqnse if set true

false

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#retObject

Returns the value of attribute ret.



10
11
12
# File 'lib/inoreader/api/helper.rb', line 10

def ret
  @ret
end

Class Method Details

.auth_request(un, pw) ⇒ Object

auth request to Inoreader

Parameters:

  • un (String)

    username

  • pw (String)

    password

Returns:

  • response body



66
67
68
69
70
71
72
73
74
# File 'lib/inoreader/api/helper.rb', line 66

def auth_request(un, pw)
  response = self.post('/accounts/ClientLogin', {:body => {:Email => un, :Passwd => pw}})
  if response.response.code == '200'
    # request fail (ex. 500, 401...)
    response.body
  else
    raise InoreaderApiError.new response.response.message
  end
end

.request(path, query = nil, method = :get) ⇒ Object

send request

Parameters:

  • path (String)

    request path

  • query (Hash) (defaults to: nil)

    URL params ex. => {:T => ‘token’, :ref => ‘bar’}

  • method (Symbol) (defaults to: :get)

    :get or :post

Returns:

  • response body



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/inoreader/api/helper.rb', line 35

def request(path, query=nil, method=:get)

  begin
    response = self.send(method, path, query)
  rescue => e
    #request fail (ex. timeout)
    raise InoreaderApiError.new e.message
  end

  if response.response.code == '200'
    if @@return_httparty_response
      response
    else
      begin
        #return to hashie
        Hashie::Mash.new MultiJson.decode(response.body)
      rescue
        # its not JSON, return body directly.
        response.body
      end
    end
  else
    # request fail (ex. 500, 401...)
    raise InoreaderApiError.new response.response.message
  end
end

.return_httparty_response=(bool) ⇒ Object



25
26
27
# File 'lib/inoreader/api/helper.rb', line 25

def return_httparty_response=(bool)
  @@return_httparty_response = bool
end