Class: Blupee::HTTPService::Request
- Inherits:
-
Object
- Object
- Blupee::HTTPService::Request
- Defined in:
- lib/blupee/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: path, verb: 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 Blupee, 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 Blupee server.
-
#verb ⇒ Object
Determines which type of request to send to Blupee.
Constructor Details
#initialize(path: path, verb: verb, args: {}, options: {}) ⇒ Request
Returns a new instance of Request.
15 16 17 18 19 20 |
# File 'lib/blupee/http_service/request.rb', line 15 def initialize(path: path, verb: 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/blupee/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/blupee/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/blupee/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/blupee/http_service/request.rb', line 4 def raw_verb @raw_verb end |
Instance Method Details
#get_args ⇒ Object
53 54 55 |
# File 'lib/blupee/http_service/request.rb', line 53 def get_args raw_verb == "get" ? args : {} end |
#json? ⇒ Boolean
Whether or not this request should use JSON.
72 73 74 |
# File 'lib/blupee/http_service/request.rb', line 72 def json? [:format] == :json end |
#options ⇒ Object
Calculates a set of request options to pass to Faraday.
any specified for the request.
61 62 63 64 65 66 67 |
# File 'lib/blupee/http_service/request.rb', line 61 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 Blupee, incorporating an API version if specified.
32 33 34 35 36 37 |
# File 'lib/blupee/http_service/request.rb', line 32 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] || Blupee.config.api_version "/#{api_version}/#{raw_path}" end |
#post_args ⇒ Object
Determines any arguments to be sent in a POST body.
other values
43 44 45 46 47 48 49 50 51 |
# File 'lib/blupee/http_service/request.rb', line 43 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 Blupee server.
79 80 81 |
# File 'lib/blupee/http_service/request.rb', line 79 def server uri = "#{[:use_ssl] ? "https" : "http"}://#{Blupee.config.api_server}" end |
#verb ⇒ Object
Determines which type of request to send to Blupee. Blupee natively accepts GETs and POSTs, for others we have to include the method in the post body.
25 26 27 |
# File 'lib/blupee/http_service/request.rb', line 25 def verb ["get", "post"].include?(raw_verb) ? raw_verb : "post" end |