Class: Koala::HTTPService::Request
- Inherits:
-
Object
- Object
- Koala::HTTPService::Request
- Defined in:
- lib/koala/http_service/request.rb
Instance Attribute Summary collapse
-
#raw_args ⇒ Object
readonly
Returns the value of attribute raw_args.
-
#raw_options ⇒ Object
readonly
Returns the value of attribute raw_options.
-
#raw_path ⇒ Object
readonly
Returns the value of attribute raw_path.
-
#raw_verb ⇒ Object
readonly
Returns the value of attribute raw_verb.
Instance Method Summary collapse
- #get_args ⇒ Object
-
#initialize(path:, verb:, args: {}, options: {}) ⇒ Request
constructor
A new instance of Request.
-
#json? ⇒ Boolean
Whether or not this request should use JSON.
-
#options ⇒ Object
Calculates a set of request options to pass to Faraday.
-
#path ⇒ Object
Determines the path to be requested on Facebook, incorporating an API version if specified.
-
#post_args ⇒ Object
Determines any arguments to be sent in a POST body.
-
#server ⇒ Object
The address of the appropriate Facebook server.
-
#verb ⇒ Object
Determines which type of request to send to Facebook.
Constructor Details
#initialize(path:, verb:, args: {}, options: {}) ⇒ Request
Returns a new instance of Request.
17 18 19 20 21 22 |
# File 'lib/koala/http_service/request.rb', line 17 def initialize(path:, verb:, args: {}, options: {}) @raw_path = path @raw_args = args @raw_verb = verb @raw_options = end |
Instance Attribute Details
#raw_args ⇒ Object (readonly)
Returns the value of attribute raw_args.
4 5 6 |
# File 'lib/koala/http_service/request.rb', line 4 def raw_args @raw_args end |
#raw_options ⇒ Object (readonly)
Returns the value of attribute raw_options.
4 5 6 |
# File 'lib/koala/http_service/request.rb', line 4 def @raw_options end |
#raw_path ⇒ Object (readonly)
Returns the value of attribute raw_path.
4 5 6 |
# File 'lib/koala/http_service/request.rb', line 4 def raw_path @raw_path end |
#raw_verb ⇒ Object (readonly)
Returns the value of attribute raw_verb.
4 5 6 |
# File 'lib/koala/http_service/request.rb', line 4 def raw_verb @raw_verb end |
Instance Method Details
#get_args ⇒ Object
61 62 63 |
# File 'lib/koala/http_service/request.rb', line 61 def get_args raw_verb == "get" ? args : {} end |
#json? ⇒ Boolean
Whether or not this request should use JSON.
80 81 82 |
# File 'lib/koala/http_service/request.rb', line 80 def json? [:format] == :json end |
#options ⇒ Object
Calculates a set of request options to pass to Faraday.
any specified for the request.
69 70 71 72 73 74 75 |
# File 'lib/koala/http_service/request.rb', line 69 def # figure out our options for this request ( # for GETs, we pass the params to Faraday to encode {params: get_args}.merge(HTTPService.).merge() ) end |
#path ⇒ Object
Determines the path to be requested on Facebook, incorporating an API version if specified.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/koala/http_service/request.rb', line 34 def path # if an api_version is specified and the path does not already contain # one, prepend it to the path api_version = [:api_version] || Koala.config.api_version if api_version && !path_contains_api_version? begins_with_slash = raw_path[0] == "/" divider = begins_with_slash ? "" : "/" "/#{api_version}#{divider}#{raw_path}" else raw_path end end |
#post_args ⇒ Object
Determines any arguments to be sent in a POST body.
other values
51 52 53 54 55 56 57 58 59 |
# File 'lib/koala/http_service/request.rb', line 51 def post_args if raw_verb == "get" {} elsif raw_verb == "post" args else args.merge(method: raw_verb) end end |
#server ⇒ Object
The address of the appropriate Facebook server.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/koala/http_service/request.rb', line 87 def server uri = "#{[:use_ssl] ? "https" : "http"}://#{Koala.config.graph_server}" # if we want to use the beta tier or the video server, make those substitutions as # appropriate replace_server_component( replace_server_component(uri, [:video], Koala.config.video_replace), [:beta], Koala.config.beta_replace ) end |
#verb ⇒ Object
Determines which type of request to send to Facebook. Facebook natively accepts GETs and POSTs, for others we have to include the method in the post body.
27 28 29 |
# File 'lib/koala/http_service/request.rb', line 27 def verb ["get", "post"].include?(raw_verb) ? raw_verb : "post" end |