Class: Facebooker::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/facebooker/service.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_base, api_path, api_key) ⇒ Service

Returns a new instance of Service.



11
12
13
14
15
# File 'lib/facebooker/service.rb', line 11

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



18
19
20
21
22
23
24
25
26
# File 'lib/facebooker/service.rb', line 18

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



60
61
62
# File 'lib/facebooker/service.rb', line 60

def post_file(params)
  Parser.parse(params[:method], post_multipart_form(url, params))
end

#post_form(url, params) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/facebooker/service.rb', line 28

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



40
41
42
43
44
45
46
# File 'lib/facebooker/service.rb', line 40

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



36
37
38
# File 'lib/facebooker/service.rb', line 36

def post_form_with_net_http(url,params)
  Net::HTTP.post_form(url, params)
end

#post_multipart_form(url, params) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/facebooker/service.rb', line 48

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



56
57
58
# File 'lib/facebooker/service.rb', line 56

def post_multipart_form_with_net_http(url,params)
  Net::HTTP.post_multipart_form(url, params)
end