Class: Pinboard::Request
- Inherits:
-
Object
show all
- Includes:
- HTTParty
- Defined in:
- lib/pinboard/request.rb
Constant Summary
collapse
- CALLS_WHITELIST =
%w(posts update add delete get dates recent all suggest tags rename user secret params)
Instance Method Summary
collapse
Constructor Details
#initialize(username, password) ⇒ Request
Returns a new instance of Request.
9
10
11
12
|
# File 'lib/pinboard/request.rb', line 9
def initialize(username, password)
self.class.basic_auth username, password
@calls = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/pinboard/request.rb', line 36
def method_missing(name, *args, &block)
return self if CALLS_WHITELIST.include?(name.to_s) == false
if name != :params
@calls.push(name)
else
@params = args[0]
end
self
end
|
Instance Method Details
#clear ⇒ Object
30
31
32
33
|
# File 'lib/pinboard/request.rb', line 30
def clear
@calls = []
return
end
|
#req ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/pinboard/request.rb', line 14
def req
raise UnableToRenderURIError if @calls.empty?
parse_params
path = @calls.join('/')
@calls = []
response = self.class.get("https://api.pinboard.in/v1/#{path}", :query => @params)
error = process_response_code(response.response.code)
raise error if error != nil
response.parsed_response
end
|