Class: ActiveJabber::Base::Request
- Inherits:
-
Object
- Object
- ActiveJabber::Base::Request
- Defined in:
- lib/activejabber.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
Returns the value of attribute parts.
Instance Method Summary collapse
-
#initialize(base, part, parts) ⇒ Request
constructor
A new instance of Request.
- #method_missing(method, *args) ⇒ Object
- #parse_format(method) ⇒ Object
Constructor Details
#initialize(base, part, parts) ⇒ Request
Returns a new instance of Request.
60 61 62 63 64 65 66 |
# File 'lib/activejabber.rb', line 60 def initialize(base, part, parts) @base = base @parts = parts unless part.nil? @parts << ('/' + part.to_s) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/activejabber.rb', line 74 def method_missing(method, *args) if args.length > 0 or self.parse_format(method) or method.to_s.ends_with? '!' format = self.parse_format(method) opts = { :format => (format or :text), :args => '' } if (args.second.is_a? Hash or args.second.nil?) and format == :json if args.first opts[:args] = (args.first.is_a?(String) ? args.first : args.first.to_json) end if args.second opts.merge! args.second end elsif args.first.is_a? Hash opts.merge! args.first elsif args.first.respond_to? :to_s opts[:args] = args.first.to_s if args.second.is_a? Hash opts.merge! args.second end end if format == :json @parts << '.json' else @parts << ('/' + method.to_s.gsub(/!$/, '')) end @base.request(@parts.join(''), opts) else Request.new(@base, method, @parts) end end |
Instance Attribute Details
#parts ⇒ Object
Returns the value of attribute parts.
58 59 60 |
# File 'lib/activejabber.rb', line 58 def parts @parts end |
Instance Method Details
#parse_format(method) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/activejabber.rb', line 67 def parse_format(method) if method.to_s == 'json' or method.to_s == 'json?' :json elsif method.to_s == 'text' or method.to_s == 'text?' :text end end |