Class: Facebooker::Service
- Inherits:
-
Object
- Object
- Facebooker::Service
- Defined in:
- lib/facebooker/service.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(api_base, api_path, api_key) ⇒ Service
constructor
A new instance of Service.
-
#post(params) ⇒ Object
TODO: support ssl.
- #post_file(params) ⇒ Object
- #post_form(url, params) ⇒ Object
- #post_form_with_curl(url, params, multipart = false) ⇒ Object
- #post_form_with_net_http(url, params) ⇒ Object
- #post_multipart_form(url, params) ⇒ Object
- #post_multipart_form_with_net_http(url, params) ⇒ Object
Constructor Details
#initialize(api_base, api_path, api_key) ⇒ Service
Returns a new instance of Service.
10 11 12 13 14 |
# File 'lib/facebooker/service.rb', line 10 def initialize(api_base, api_path, api_key) @api_base = api_base @api_path = api_path @api_key = api_key end |
Instance Method Details
#post(params) ⇒ Object
TODO: support ssl
17 18 19 20 21 22 23 24 25 |
# File 'lib/facebooker/service.rb', line 17 def post(params) attempt = 0 Parser.parse(params[:method], post_form(url,params) ) rescue Errno::ECONNRESET, EOFError if attempt == 0 attempt += 1 retry end end |
#post_file(params) ⇒ Object
59 60 61 62 63 |
# File 'lib/facebooker/service.rb', line 59 def post_file(params) service_url = url(params.delete(:base)) result = post_multipart_form(service_url, params) Parser.parse(params[:method], result) end |
#post_form(url, params) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/facebooker/service.rb', line 27 def post_form(url,params) if Facebooker.use_curl? post_form_with_curl(url,params) else post_form_with_net_http(url,params) end end |
#post_form_with_curl(url, params, multipart = false) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/facebooker/service.rb', line 39 def post_form_with_curl(url,params,multipart=false) response = Curl::Easy.http_post(url.to_s, *to_curb_params(params)) do |c| c.multipart_form_post = multipart c.timeout = Facebooker.timeout end response.body_str end |
#post_form_with_net_http(url, params) ⇒ Object
35 36 37 |
# File 'lib/facebooker/service.rb', line 35 def post_form_with_net_http(url,params) Net::HTTP.post_form(url, params) end |
#post_multipart_form(url, params) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/facebooker/service.rb', line 47 def post_multipart_form(url,params) if Facebooker.use_curl? post_form_with_curl(url,params,true) else post_multipart_form_with_net_http(url,params) end end |
#post_multipart_form_with_net_http(url, params) ⇒ Object
55 56 57 |
# File 'lib/facebooker/service.rb', line 55 def post_multipart_form_with_net_http(url,params) Net::HTTP.post_multipart_form(url, params) end |