Class: Tmdby::Wrapper
- Inherits:
-
Object
- Object
- Tmdby::Wrapper
- Defined in:
- lib/tmdby/wrapper.rb
Direct Known Subclasses
Account, Authentication, Certifications, Changes, Collections, Companies, Configuration, Credits, Discover, Find, Genres, GuestSessions, Jobs, Keywords, Lists, Movies, Networks, People, Reviews, Search, Timezones, Tv, TvEpisodes, TvSeasons
Class Attribute Summary collapse
-
.clean_params ⇒ Object
Returns the value of attribute clean_params.
-
.params ⇒ Object
Returns the value of attribute params.
-
.post_params ⇒ Object
Returns the value of attribute post_params.
-
.root ⇒ Object
Returns the value of attribute root.
Class Method Summary collapse
-
.add_default_language ⇒ Object
Add default language to parameters if it has been setted.
- .fetch(route = "", *args) ⇒ Object
-
.handle_post_params(post_param_names) ⇒ Object
Dispatch params in 2 hashes : one for api url parameters, another on for api post parameters.
-
.route(route) ⇒ Object
Compute api route.
-
.verify_params(authorized) ⇒ Object
Verify that every parameter is allowed by the api.
Class Attribute Details
.clean_params ⇒ Object
Returns the value of attribute clean_params.
4 5 6 |
# File 'lib/tmdby/wrapper.rb', line 4 def clean_params @clean_params end |
.params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/tmdby/wrapper.rb', line 4 def params @params end |
.post_params ⇒ Object
Returns the value of attribute post_params.
4 5 6 |
# File 'lib/tmdby/wrapper.rb', line 4 def post_params @post_params end |
.root ⇒ Object
Returns the value of attribute root.
4 5 6 |
# File 'lib/tmdby/wrapper.rb', line 4 def root @root end |
Class Method Details
.add_default_language ⇒ Object
Add default language to parameters if it has been setted
26 27 28 29 30 31 32 |
# File 'lib/tmdby/wrapper.rb', line 26 def self.add_default_language default_language = Tmdby::Setup.default_language if default_language && !@params.key?('language') && !@params.key?(:language) @params['language'] = default_language end end |
.fetch(route = "", *args) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/tmdby/wrapper.rb', line 48 def self.fetch(route = "", *args) if args.length == 0 = {} elsif args.length == 1 = args[0] elsif args.length == 2 = args[1].merge(args[0]) end method = .fetch(:method, 'get') post_params = .fetch(:post_params, []) = .fetch(:authorized_params, []) disable_unknown_params = .fetch(:disable_unknown_params, false) [:method, :post_params, :authorized_params, :disable_unknown_params].each do |key| .delete(key) end @params = self.add_default_language if .include?'language' self.verify_params unless disable_unknown_params or .include?"append_to_response" self.handle_post_params post_params Tmdby::Client.api_call method, self.route(route), @clean_params, @post_params end |
.handle_post_params(post_param_names) ⇒ Object
Dispatch params in 2 hashes : one for api url parameters, another on for api post parameters
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tmdby/wrapper.rb', line 35 def self.handle_post_params(post_param_names) @clean_params = {} @post_params = {} @params.each do |k, v| if post_param_names.include?k or post_param_names.include?k.to_s @post_params[k.to_s] = v if v else @clean_params[k.to_s] = v if v end end end |
.route(route) ⇒ Object
Compute api route
8 9 10 11 12 13 14 15 16 |
# File 'lib/tmdby/wrapper.rb', line 8 def self.route(route) route = route.to_s if route.is_a? Integer if @root and not @root.empty? and not route.empty? "#{@root}/#{route}" else "#{@root}#{route}" end end |
.verify_params(authorized) ⇒ Object
Verify that every parameter is allowed by the api
19 20 21 22 23 |
# File 'lib/tmdby/wrapper.rb', line 19 def self.verify_params() @params.each do |key, _| raise RuntimeError, "Unknown argument : #{key}\nAuthorized arguments : #{.join(', ')}" if not .include? key.to_s end end |