Class: Curly
- Inherits:
-
ActiveSupport::BasicObject
- Defined in:
- lib/highrise/curly.rb
Defined Under Namespace
Classes: Form
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(uri = nil) {|_self| ... } ⇒ Curly
Returns a new instance of Curly.
9
10
11
12
13
14
|
# File 'lib/highrise/curly.rb', line 9
def initialize(uri = nil)
@curl = Curl::Easy.new
self.uri = uri
self.follow_location = true
yield self if block_given?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
35
36
37
|
# File 'lib/highrise/curly.rb', line 35
def method_missing(method, *args, &block)
@curl.send(method, *args, &block)
end
|
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
7
8
9
|
# File 'lib/highrise/curly.rb', line 7
def uri
@uri
end
|
Instance Method Details
#cookiejar=(filename) ⇒ Object
39
40
41
42
|
# File 'lib/highrise/curly.rb', line 39
def cookiejar=(filename)
self.enable_cookies = true
@curl.cookiejar = filename
end
|
#doc ⇒ Object
55
56
57
|
# File 'lib/highrise/curly.rb', line 55
def doc
Hpricot body_unicode
end
|
#encoding ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/highrise/curly.rb', line 59
def encoding
return @encoding unless @encoding == false
@encoding = if body_str =~ /;\s*charset=([\w-]+)\s*['"]/
$1.downcase
else
false
end
end
|
#get(uri = nil) ⇒ Object
44
45
46
47
48
49
|
# File 'lib/highrise/curly.rb', line 44
def get(uri = nil)
self.uri = uri
http_get
raise "expected 2xx, got #{response_code} (GET #{url})" unless success?
self
end
|
#post(params) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/highrise/curly.rb', line 68
def post(params)
fields = params.map do |key, value|
Curl::PostField.content(key.to_s, value.to_s)
end
http_post *fields
end
|
#success? ⇒ Boolean
51
52
53
|
# File 'lib/highrise/curly.rb', line 51
def success?
response_code >= 200 and response_code < 300
end
|