lib/rubytter.rb in jugyo-rubytter-0.6.4 vs lib/rubytter.rb in jugyo-rubytter-0.6.5

- old
+ new

@@ -14,11 +14,11 @@ super(msg) @response = response end end - VERSION = '0.6.3' + VERSION = '0.6.5' attr_reader :login attr_accessor :host, :header def initialize(login = nil, password = nil, options = {}) @@ -123,20 +123,20 @@ path = path + param_str unless param_str.empty? req = create_request(Net::HTTP::Get.new(path), false) json_data = http_request("search.#{@host}", req) self.class.json_to_struct( json_data['results'].map do |result| - search_result_to_struct(result) + self.class.search_result_to_hash(result) end ) end - def search_result_to_struct(json) + def self.search_result_to_hash(json) { 'id' => json['id'], 'text' => json['text'], - 'source' => CGI.unescapeHTML(json['source']), + 'source' => json['source'], 'created_at' => json['created_at'], 'in_reply_to_user_id' => json['to_usre_id'], 'in_reply_to_screen_name' => json['to_usre'], 'in_reply_to_status_id' => nil, 'user' => { @@ -182,19 +182,32 @@ when String, Symbol struct_values[k.to_sym] = json_to_struct(v) end end unless struct_values.empty? - Struct.new(*struct_values.keys).new(*struct_values.values) + get_struct(struct_values.keys).new(*struct_values.values) else nil end else - json + case json + when String + CGI.unescapeHTML(json) + else + json + end end end def self.to_param_str(hash) raise ArgumentError, 'Argument must be a Hash object' unless hash.is_a?(Hash) hash.to_a.map{|i| i[0].to_s + '=' + CGI.escape(i[1].to_s) }.join('&') + end + + def self.get_struct(keys) + @@structs ||= {} + unless @@structs.has_key?(keys) + @@structs[keys] = Struct.new(*keys) + end + @@structs[keys] end end