socialcastr 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -45,6 +45,11 @@ SocialCast gem is a ruby interface to the SocialCast REST API
45
45
 
46
46
  This is just the first draft of the wrapper. It can be improved in many, many ways.
47
47
  The API is not completely covered either: some of interesing stuff, like message and comments attachments have been left out.
48
+ One current limitation is that the parser will refuse to consider
49
+ elements that contain a dot, so I'm excluding those deliberately for the
50
+ time being (see
51
+ lib/socialcastr/sax/active_resource.rb#start_element).
52
+
48
53
  Feel free to help (see Contributing below)
49
54
 
50
55
  ## TODO
@@ -0,0 +1,87 @@
1
+ $:.unshift("./lib")
2
+ require "rubygems"
3
+ require "nokogiri"
4
+
5
+ class ActiveResourceXML < Nokogiri::XML::SAX::Document
6
+ attr_accessor :doc
7
+ def initialize
8
+ @types = []
9
+ @values = []
10
+ @doc = nil
11
+ end
12
+
13
+ def parse_attrs(attrs=[])
14
+ type = "hash"
15
+ attrs.each do |attr|
16
+ case attr[0]
17
+ when "type"
18
+ type = attr[1]
19
+ when "nil"
20
+ @nil = true
21
+ end
22
+ end
23
+ return type
24
+ end
25
+
26
+ def start_element name, attrs = []
27
+ type = parse_attrs(attrs)
28
+ unless @nil
29
+ @types.push type
30
+ case type
31
+ when "array"
32
+ @values.push Array.new
33
+ when "hash"
34
+ @values.push Hash.new
35
+ else
36
+ @values.push ""
37
+ end
38
+ end
39
+ end
40
+
41
+ def characters(s)
42
+ return if s =~ /^[\s\n\t]*$/
43
+ @types[-1] = "string"
44
+ @values[-1] = s
45
+ end
46
+
47
+ def end_element name
48
+ if @nil
49
+ @nil = false
50
+ else
51
+ value = @values.pop
52
+ type = @types.pop
53
+
54
+ if @values[-1]
55
+ if @types[-1] == "array"
56
+ @values[-1].push value
57
+ else
58
+ @values[-1][name] = value
59
+ end
60
+ else
61
+ @doc = { name => value }
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+
68
+ class Message
69
+ def self.parse(xml="")
70
+ source= ActiveResourceXML.new
71
+ parser = Nokogiri::XML::SAX::Parser.new(source)
72
+ parser.parse(xml)
73
+ return source
74
+ end
75
+ end
76
+
77
+
78
+ xml = File.read("/Users/bru/Downloads/socialcast.xml")
79
+ start_time = Time.new
80
+ document = Message.parse(xml)
81
+ end_time = Time.new
82
+
83
+ puts "File parsed in #{end_time - start_time} seconds"
84
+ puts "Found #{document.doc["messages"].size} messages"
85
+
86
+
87
+
@@ -8,9 +8,9 @@ Socialcastr.configuration do |config|
8
8
  config.domain = "domain"
9
9
  end
10
10
 
11
- xml = File.read("~/Download/socialcast.xml")
11
+ xml = File.read("/Users/bru/Downloads/socialcast.xml")
12
12
  start_time = Time.new
13
- messages = Socialcastr::Message.parse_collection(xml)
13
+ messages = Socialcastr::Message.parse(xml)
14
14
  end_time = Time.new
15
15
 
16
16
  puts "Found #{messages.count} messages in #{end_time - start_time} seconds"
@@ -1,21 +1,11 @@
1
- require 'sax-machine'
2
-
1
+ require 'nokogiri'
2
+ require 'socialcastr/sax/active_resource'
3
3
  module Socialcastr
4
4
  class Base
5
- include SAXMachine
6
-
7
5
  def initialize(arguments={})
6
+ @data = {}
8
7
  arguments.map do |k,v|
9
- self.send((k.to_s + "=").to_sym, v)
10
- end
11
- end
12
-
13
- def id
14
- begin
15
- tmp_id = send self.class.id_attribute
16
- tmp_id.to_i unless tmp_id.nil?
17
- rescue
18
- nil
8
+ @data[k.to_s] = v
19
9
  end
20
10
  end
21
11
 
@@ -36,9 +26,7 @@ module Socialcastr
36
26
  end
37
27
 
38
28
  def copy_attributes_from_object(object=nil)
39
- object.instance_variables.each do |v|
40
- instance_variable_set(v, object.instance_variable_get(v))
41
- end
29
+ @data = object.instance_variable_get("@data")
42
30
  end
43
31
 
44
32
  def new?
@@ -59,17 +47,48 @@ module Socialcastr
59
47
 
60
48
  def to_params
61
49
  params = {}
62
- instance_variables.each do |variable|
63
- params[param_name(variable)] = instance_variable_get(variable)
50
+ @data.each_pair do |k,v|
51
+ params[param_name(k)] = v
64
52
  end
65
53
  params
66
54
  end
67
55
 
68
56
  def param_name(variable_name)
69
- "#{self.class.model_name.downcase}[#{variable_name.to_s.gsub /@/,''}]"
57
+ "#{self.class.model_name.downcase}[#{variable_name}]"
58
+ end
59
+
60
+ def method_name(s)
61
+ s.to_s.gsub("_","-")
62
+ end
63
+
64
+ def id
65
+ return @data["id"]
66
+ end
67
+
68
+ def method_missing(method, *args, &block)
69
+ if method.to_s =~ /=$/
70
+ @data[method_name(method.to_s.sub(/=$/,''))] = *args
71
+ else
72
+ return @data[method_name(method)] unless @data[method_name(method)].nil?
73
+ end
70
74
  end
71
75
 
72
76
  class << self
77
+ def parse(xml="")
78
+ source = SAX::ActiveResource.new
79
+ Nokogiri::XML::SAX::Parser.new(source).parse(xml)
80
+ case source.data
81
+ when Hash
82
+ return from_hash(source.data)
83
+ else
84
+ return source.data
85
+ end
86
+ end
87
+
88
+ def from_hash(h)
89
+ new.tap { |object| object.instance_variable_set("@data", h) }
90
+ end
91
+
73
92
  def api
74
93
  @api ||= Socialcastr.api
75
94
  end
@@ -95,7 +114,7 @@ module Socialcastr
95
114
  def find_every(options)
96
115
  (prefix_options, query_options) = parse_options(options)
97
116
  path = collection_path(prefix_options)
98
- parse_collection(api.get(path, query_options))
117
+ parse(api.get(path, query_options))
99
118
  end
100
119
 
101
120
  def all(*arguments)
@@ -140,31 +159,6 @@ module Socialcastr
140
159
  def collection_name
141
160
  model_name.downcase + "s"
142
161
  end
143
-
144
- def parse_collection(data)
145
- collection_class.parse(data)
146
- end
147
-
148
- def id_attribute
149
- model_name.downcase + "_id"
150
- end
151
-
152
- def collection_class
153
- return @collection_class if @collection_class
154
- class_name = model_name + "List"
155
- model_class = self
156
- c_element = model_name.downcase.to_sym
157
- c_name = collection_name.to_sym
158
- klass = Object.const_set(class_name,Class.new(Socialcastr::Collection))
159
- klass.class_eval do
160
- collection_of c_element, :as => c_name, :class => model_class
161
- end
162
- return @collection_class = klass
163
- end
164
-
165
- def id_element(name=:id)
166
- element name, :as => id_attribute.to_sym
167
- end
168
162
  end
169
163
  end
170
164
  end
@@ -1,19 +1,5 @@
1
1
  module Socialcastr
2
2
  class Comment < Base
3
- element :editable
4
- elements :attachment, :as => :attachments, :class => Socialcastr::Attachment
5
- element :likable
6
- element :deletable
7
- elements :like, :as => :likes, :class => Socialcastr::Like
8
- element :permalink_url
9
- element :text
10
- element :user, :class => Socialcastr::User
11
- element :thumbnail_url
12
- element :url
13
- element :likes_count
14
- element :"created-at", :as => :created_at
15
- element :id
16
-
17
3
  def unlikable_by?(api_id)
18
4
  self.likes.map{|l| l.unlikable_by?(api_id)}.any?
19
5
  end
@@ -1,9 +1,5 @@
1
1
  module Socialcastr
2
2
  class Like < Base
3
- id_element
4
- element :unlikable
5
- element :user, :class => Socialcastr::User
6
- element :"created-at", :as => :created_at
7
3
  def unlikable_by?(api_id)
8
4
  @unlikable && api_id == self.user_id ? true : false
9
5
  end
@@ -1,74 +1,29 @@
1
1
  module Socialcastr
2
- class Message < Base
3
-
4
- id_element :id
5
- element :title
6
- element :body
7
- element :url
8
- element "permalink-url", :as => :permalink_url
9
- element :action
10
- element "external-url", :as => :external_url
11
- element :icon
12
- element :likable
13
- element "created-at", :as => :created_at
14
- element "updated-at", :as => :updated_at
15
- element "last-interacted-at", :as => :last_interacted_at
16
- element "player-url", :as => :player_url
17
- element "thumbnail-url", :as => :thumbnail_url
18
- element "player-params", :as => :player_params
19
- element :user, :class => Socialcastr::User
20
- #element :group, :class => Socialcastr::Group
21
- elements :group, :as => :groups, :class => Socialcastr::Group
22
- element :source, :class => Socialcastr::Source
23
-
24
- element :editable
25
- element :rating
26
- element "category-id", :as => :category_id
27
- element :subscribed
28
- # element :ratings_average
29
- element :flag, :class => Socialcastr::Flag
30
- element :deletable
31
- element "comments-count", :as => :comments_count
32
- element :verb
33
- element "in-reply-to", :as => :in_reply_to
34
- element :watchable
35
- element "contains-url-only", :as => :contains_url_only
36
- # element :target_user
37
- element :ratable
38
- element "message-type", :as => :message_type
39
- elements :recipient, :as => :recipients, :class => Socialcastr::Recipient
40
2
 
41
- elements :attachment, :as => :attachments, :class => Socialcastr::Attachment
42
- elements :tag, :as => :tags, :class => Socialcastr::Tag
43
- elements :like, :as => :likes, :class => Socialcastr::Like
44
- elements "external-resource", :as => :external_resources, :class => Socialcastr::ExternalResource
45
- elements "media-file", :as => :media_files, :class => Socialcastr::MediaFile
46
- element "likes-count", :as => :likes_count
47
- element :hidden
48
-
49
- elements :comment, :as => :comments, :class => Socialcastr::Comment
3
+ class Message < Base
50
4
 
51
5
  def flag!
52
6
  return true if flagged?
53
- flag.copy_attributes_from_object(Flag.parse(api.post(element_path + "/flags")))
7
+ self.flag = Socialcastr::Flag.parse(api.post(element_path + "/flags"))
54
8
  end
55
9
 
56
10
  def flagged?
57
- !flag.id.nil?
11
+ self.flag && !self.flag.id.nil?
58
12
  end
59
13
 
60
14
  def unflag!
61
15
  return unless flagged?
62
- api.delete(element_path + "/flags/#{flag.id}")
63
- @flag = Flag.new
16
+ api.delete(element_path + "/flags/#{self.flag.id}")
17
+ self.flag = nil
64
18
  end
65
19
 
66
20
  def like!
21
+ self.likes ||= []
67
22
  likes << Like.parse(api.post(element_path + "/likes"))
68
23
  end
69
24
 
70
25
  def unlike!
71
- likes.reject! do |l|
26
+ self.likes.reject! do |l|
72
27
  l.unlikable && api.delete(element_path + "/likes/#{l.id}")
73
28
  end
74
29
  end
@@ -79,8 +34,11 @@ module Socialcastr
79
34
  end
80
35
 
81
36
 
82
- def self.search(arguments={})
83
- parse_collection(api.get(collection_path + "/search", arguments))
37
+ def self.search(query, arguments={})
38
+ puts "searching for #{query}"
39
+ xml = api.get(collection_path + "/search", { :q => query}.merge(arguments))
40
+ puts "Got a response xml of #{xml.length} bytes"
41
+ return parse(xml)
84
42
  end
85
43
  end
86
44
  end
@@ -0,0 +1,119 @@
1
+ class Boolean
2
+ def initialize(string)
3
+ return true if string == "true"
4
+ return false
5
+ end
6
+ end
7
+
8
+ class String
9
+ def contains_dot?
10
+ self =~ /\./
11
+ end
12
+
13
+ def all_spaces?
14
+ self =~ /^[\s\n\t]*$/
15
+ end
16
+ end
17
+
18
+ module Socialcastr
19
+ module SAX
20
+
21
+ class ActiveResource < Nokogiri::XML::SAX::Document
22
+ attr_accessor :data
23
+
24
+ def initialize
25
+ @types = []
26
+ @values = []
27
+ @data= nil
28
+ end
29
+
30
+ def cdata_block(s)
31
+ characters(s)
32
+ end
33
+
34
+ HASH = 104 # 'h'
35
+ ARRAY = 97 # 'a'
36
+ INTEGER = 105 # 'i'
37
+ BOOLEAN = 98 # 'b'
38
+ STRING = 115 # 's'
39
+
40
+ def container_type
41
+ @types[-1]
42
+ end
43
+
44
+ def container_value
45
+ @values[-1]
46
+ end
47
+
48
+ def parse_attrs_and_get_type(attrs=[])
49
+ type = HASH
50
+ attrs.each do |attr|
51
+ case attr[0]
52
+ when "type"
53
+ type = attr[1][0]
54
+ when "nil"
55
+ @nil = true
56
+ end
57
+ end
58
+ return type
59
+ end
60
+
61
+ def start_element name, attrs = []
62
+ if name.contains_dot? # [FIXME] we can't evaluate strings inside elements like <html.title>
63
+ @nil = true
64
+ return nil
65
+ end
66
+ type = parse_attrs_and_get_type(attrs)
67
+ unless @nil
68
+ @types.push type
69
+ @values.push nil
70
+ end
71
+ end
72
+
73
+ def characters string
74
+ return if @nil
75
+ return if (string.all_spaces? && (container_type != STRING || container_value.nil?))
76
+ @types[-1] = STRING if container_type == HASH
77
+ @values[-1] = container_value ? container_value + string : string
78
+ end
79
+
80
+ def end_element name
81
+ if @nil
82
+ @nil = false
83
+ else
84
+ value = @values.pop
85
+ type = @types.pop
86
+
87
+ # return if value.nil?
88
+
89
+ case type
90
+ when HASH
91
+ element = Socialcastr.const_get(Socialcastr.to_class_name(name)).from_hash(value || {})
92
+ when INTEGER
93
+ element = value.to_i
94
+ when BOOLEAN
95
+ element = Boolean.new(value)
96
+ when ARRAY
97
+ element = value || []
98
+ else
99
+ element = value
100
+ end
101
+
102
+ if container_type
103
+ if container_type == ARRAY
104
+ # @values[-1] ||= []
105
+ # @values[-1].push element
106
+ @values[-1] ? @values[-1].push(element) : @values[-1] = [element]
107
+ else # Hash
108
+ # @values[-1] ||= {}
109
+ # @values[-1][name] = element
110
+ @values[-1] ? @values[-1][name]=element : @values[-1] = { name => element }
111
+ end
112
+ else # Root Node
113
+ @data = element
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -1,3 +1,3 @@
1
1
  module Socialcastr
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/socialcastr.rb CHANGED
@@ -2,23 +2,9 @@ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.i
2
2
 
3
3
  require 'socialcastr/exceptions'
4
4
  require 'socialcastr/base'
5
- require 'socialcastr/collection'
6
5
  require 'socialcastr/api'
7
- require 'socialcastr/attachment'
8
- require 'socialcastr/avatar_list'
9
- require 'socialcastr/user'
10
- require 'socialcastr/flag'
11
6
  require 'socialcastr/like'
12
7
  require 'socialcastr/comment'
13
- require 'socialcastr/group'
14
- require 'socialcastr/group_membership'
15
- require 'socialcastr/stream'
16
- require 'socialcastr/source'
17
- require 'socialcastr/tag'
18
- require 'socialcastr/recipient'
19
- require 'socialcastr/thumbnail_list'
20
- require 'socialcastr/media_file'
21
- require 'socialcastr/external_resource'
22
8
  require 'socialcastr/message'
23
9
 
24
10
  require 'singleton'
@@ -53,25 +39,34 @@ module Socialcastr
53
39
  end
54
40
  end
55
41
 
56
- def self.configuration
57
- if block_given?
58
- yield Configuration.instance
59
- if Configuration.instance.config_file
60
- config = YAML::load_file(Configuration.instance.config_file)
61
- Configuration.instance.domain = config['domain']
62
- Configuration.instance.username = config['username']
63
- Configuration.instance.password = config['password']
64
- Configuration.instance.format = config['format']
65
- Configuration.instance.debug = config['debug']
66
- end
67
- end
68
- Configuration.instance
69
- end
42
+ class << self
43
+ def configuration
44
+ if block_given?
45
+ yield Configuration.instance
46
+ if Configuration.instance.config_file
47
+ config = YAML::load_file(Configuration.instance.config_file)
48
+ Configuration.instance.domain = config['domain']
49
+ Configuration.instance.username = config['username']
50
+ Configuration.instance.password = config['password']
51
+ Configuration.instance.format = config['format']
52
+ Configuration.instance.debug = config['debug']
53
+ end
54
+ end
55
+ Configuration.instance
56
+ end
57
+
58
+ def api
59
+ config = Configuration.instance
60
+ raise MissingConfiguration unless config.username
61
+ API.new(config.username, config.password, config.domain, config.format, config.debug)
62
+ end
63
+
64
+ def to_class_name(method)
65
+ method.to_s.gsub(/^[a-z]|-[a-z]/i) { |a| a.sub("-", '').upcase }
66
+ end
70
67
 
71
- def self.api
72
- config = Configuration.instance
73
- raise MissingConfiguration unless config.username
74
- API.new(config.username, config.password, config.domain, config.format, config.debug)
68
+ def const_missing(class_name)
69
+ Socialcastr.const_set(class_name, Class.new(Socialcastr::Base))
70
+ end
75
71
  end
76
-
77
72
  end
data/spec/base_spec.rb CHANGED
@@ -27,9 +27,7 @@ describe Socialcastr::Base do
27
27
 
28
28
  context 'for a class that has an element \'author\'' do
29
29
  before :each do
30
- class Post < Socialcastr::Base
31
- element 'author'
32
- end
30
+ class Post < Socialcastr::Base; end
33
31
  @post = Post.new
34
32
  end
35
33
 
@@ -45,10 +43,7 @@ describe Socialcastr::Base do
45
43
 
46
44
  context 'initializing a new object with author="john doe"' do
47
45
  before :each do
48
- class Post < Socialcastr::Base
49
- id_element :id
50
- element 'author'
51
- end
46
+ class Post < Socialcastr::Base; end
52
47
  @post = Post.new(:author => "john doe")
53
48
  end
54
49
 
@@ -78,7 +73,7 @@ describe Socialcastr::Base do
78
73
 
79
74
  context '#param_name' do
80
75
  it 'should return a string like model_name[variable_name]' do
81
- @post.param_name("@author").should == "post[author]"
76
+ @post.param_name("author").should == "post[author]"
82
77
  end
83
78
  end
84
79
 
@@ -96,7 +91,7 @@ describe Socialcastr::Base do
96
91
  Socialcastr.stub!(:api).and_return(@api)
97
92
  end
98
93
  it 'should POST to the socialcast api' do
99
- response = "<post><id>4</id><author>john doe</author></post>"
94
+ response = "<post><id type='integer'>4</id><author>john doe</author></post>"
100
95
  @api.should_receive(:post).and_return(response)
101
96
  @post.save
102
97
  @post.id.should == 4
@@ -143,19 +138,19 @@ describe Socialcastr::Base do
143
138
 
144
139
  context 'find_every or find(:all)' do
145
140
  before :each do
146
- fake_socialcast_api_for(:message) do
141
+ fake_socialcast_api_for(:messages) do
147
142
  @messages = Socialcastr::Base.find(:all)
148
143
  end
149
144
  end
150
145
 
151
146
  it 'should return an enumerable' do
152
- @messages.class.should == BaseList
147
+ @messages.class.should == Array
153
148
  lambda { @messages.first }.should_not raise_error
154
149
  end
155
150
  end
156
151
  context 'first or find(:first)' do
157
152
  before :each do
158
- fake_socialcast_api_for(:message) do
153
+ fake_socialcast_api_for(:messages) do
159
154
  @message = Socialcastr::Message.first
160
155
  end
161
156
  end
@@ -203,19 +198,6 @@ describe Socialcastr::Base do
203
198
  end
204
199
  end
205
200
 
206
- context 'collection_class' do
207
- before do
208
- class Post < Socialcastr::Base; end
209
- end
210
- it 'should return a class' do
211
- Post.collection_class.class.should == Class
212
- end
213
-
214
- it 'should return a class that inherits from Socialcastr::Collection' do
215
- Post.collection_class.superclass.should == Socialcastr::Collection
216
- end
217
- end
218
-
219
201
  context 'element_path' do
220
202
  context 'with 5 as an argument' do
221
203
  it 'should return collection_name/5' do
data/spec/message_spec.rb CHANGED
@@ -33,10 +33,6 @@ describe Socialcastr::Message do
33
33
  @message.groups.class.should == Array
34
34
  end
35
35
 
36
- it "should belong to a well formed group" do
37
- @message.groups.first.class.should == Socialcastr::Group
38
- end
39
-
40
36
  it "should have a source" do
41
37
  @message.source.should_not be_nil
42
38
  @message.source.class.should == Socialcastr::Source
@@ -51,8 +47,8 @@ describe Socialcastr::Message do
51
47
  end
52
48
  end
53
49
 
54
- it "should be an instance of MessageList" do
55
- @messages.class.should == MessageList
50
+ it "should be an instance of Array" do
51
+ @messages.class.should == Array
56
52
  end
57
53
 
58
54
  it "should be a collection of 20 Socialcastr::Message objects" do
@@ -75,7 +71,7 @@ describe Socialcastr::Message do
75
71
  @message = Socialcastr::Message.find(425)
76
72
  end
77
73
  @api = mock(:api)
78
- response = "<flag><id>3333</id></flag>"
74
+ response = "<flag><id type='integer'>3333</id></flag>"
79
75
  Socialcastr::Message.stub!(:api).and_return(@api)
80
76
  @api.stub!(:post).and_return(response)
81
77
  end
@@ -91,9 +87,14 @@ describe Socialcastr::Message do
91
87
  @api.should_receive(:delete).with("/messages/425/flags/3333").and_return("")
92
88
  end
93
89
 
90
+ it "should not be flagged afterwards" do
91
+ @message.unflag!
92
+ @message.flagged?.should be_false
93
+ end
94
+
94
95
  it "should not have a flag afterwards" do
95
96
  @message.unflag!
96
- @message.flag.id.should be_nil
97
+ @message.flag.should be_nil
97
98
  end
98
99
  end
99
100
  end
@@ -105,7 +106,7 @@ describe Socialcastr::Message do
105
106
  end
106
107
 
107
108
  @api = mock(:api)
108
- response = "<like><id>2222</id><unlikable>true</unlikable></like>"
109
+ response = "<like><id type='integer'>2222</id><unlikable>true</unlikable></like>"
109
110
  Socialcastr::Message.stub!(:api).and_return(@api)
110
111
  @api.stub!(:post).and_return(response)
111
112
  end
@@ -124,7 +125,7 @@ describe Socialcastr::Message do
124
125
 
125
126
  context "unliking a message" do
126
127
  before :each do
127
- fake_socialcast_api_for :message do
128
+ fake_socialcast_api_for :message do
128
129
  @message = Socialcastr::Message.find(425)
129
130
  end
130
131
 
@@ -134,6 +135,7 @@ describe Socialcastr::Message do
134
135
  @api.stub!(:post).and_return(response)
135
136
  @api.stub!(:delete).and_return("")
136
137
  @message.like!
138
+ @message.likes.count.should == 1
137
139
  end
138
140
 
139
141
  it "should remove a like" do
@@ -145,12 +147,13 @@ describe Socialcastr::Message do
145
147
 
146
148
  context "searching for messages matching 'trying'" do
147
149
  before :each do
148
- fake_socialcast_api_for :message
150
+ fake_socialcast_api_for :messages
149
151
  end
150
152
 
151
153
  it "should return a message" do
152
- @messages = Socialcastr::Message.search(:q=>"trying")
153
- @messages.size.should == 1
154
+ @messages = Socialcastr::Message.search("trying")
155
+ puts "@messages is a #{@message.class}"
156
+ @messages.size.should == 20
154
157
  end
155
158
  end
156
159
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialcastr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Riccardo Cambiassi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-17 00:00:00 +01:00
18
+ date: 2011-05-20 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -105,31 +105,19 @@ files:
105
105
  - LICENSE.markdown
106
106
  - README.markdown
107
107
  - Rakefile
108
+ - examples/free_parse_messages.rb
108
109
  - examples/parse_messages.rb
109
110
  - examples/post_comment.rb
110
111
  - examples/post_message.rb
111
112
  - examples/search.rb
112
113
  - lib/socialcastr.rb
113
114
  - lib/socialcastr/api.rb
114
- - lib/socialcastr/attachment.rb
115
- - lib/socialcastr/avatar_list.rb
116
115
  - lib/socialcastr/base.rb
117
- - lib/socialcastr/collection.rb
118
116
  - lib/socialcastr/comment.rb
119
117
  - lib/socialcastr/exceptions.rb
120
- - lib/socialcastr/external_resource.rb
121
- - lib/socialcastr/flag.rb
122
- - lib/socialcastr/group.rb
123
- - lib/socialcastr/group_membership.rb
124
118
  - lib/socialcastr/like.rb
125
- - lib/socialcastr/media_file.rb
126
119
  - lib/socialcastr/message.rb
127
- - lib/socialcastr/recipient.rb
128
- - lib/socialcastr/source.rb
129
- - lib/socialcastr/stream.rb
130
- - lib/socialcastr/tag.rb
131
- - lib/socialcastr/thumbnail_list.rb
132
- - lib/socialcastr/user.rb
120
+ - lib/socialcastr/sax/active_resource.rb
133
121
  - lib/socialcastr/version.rb
134
122
  - socialcastr.gemspec
135
123
  - spec/api_spec.rb
@@ -1,10 +0,0 @@
1
- module Socialcastr
2
- class Attachment < Base
3
- element :public_filename
4
- element :content_type
5
- element :url
6
- element :file_extension
7
- element :filename
8
- element :id
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- module Socialcastr
2
- class AvatarList < Base
3
- element :square16
4
- element :square30
5
- element :square45
6
- element :square70
7
- element :square140
8
- end
9
- end
@@ -1,30 +0,0 @@
1
- module Socialcastr
2
- class Collection < Base
3
- include Enumerable
4
-
5
- def each &block
6
- members.each{|member| block.call(member)}
7
- end
8
-
9
- def size
10
- members.size
11
- end
12
-
13
- def members
14
- send self.class.members_method
15
- end
16
-
17
- def self.collection_of(name, options={})
18
- if options[:as]
19
- @members_method = options[:as]
20
- else
21
- @members_method = name
22
- end
23
- elements name, options
24
- end
25
-
26
- def self.members_method
27
- @members_method
28
- end
29
- end
30
- end
@@ -1,14 +0,0 @@
1
- module Socialcastr
2
- class ExternalResource < Base
3
- element :type
4
- elements :tag, :as => :tags, :class => Socialcastr::Tag
5
- element :canonical_hashtag
6
- element :source, :class => Socialcastr::Source
7
- elements :media_file, :as => :media_files, :class => Socialcastr::MediaFile
8
- element :url
9
- element :title
10
- element :description
11
- element :id
12
-
13
- end
14
- end
@@ -1,5 +0,0 @@
1
- module Socialcastr
2
- class Flag < Base
3
- id_element
4
- end
5
- end
@@ -1,9 +0,0 @@
1
- module Socialcastr
2
- class Group < Base
3
- element :url
4
- element :id
5
- element :name
6
- element :avatars, :class => Socialcastr::AvatarList
7
-
8
- end
9
- end
@@ -1,6 +0,0 @@
1
- module Socialcastr
2
- class GroupMembership < Base
3
- element :group, :class => Socialcastr::Group
4
- element :role
5
- end
6
- end
@@ -1,12 +0,0 @@
1
- module Socialcastr
2
- class MediaFile < Base
3
- element :external_resource_id
4
- element :page_url
5
- element :attachment_id
6
- element :content_type
7
- element :url
8
- element :thumbnails, :class => Socialcastr::ThumbnailList
9
- element :title
10
- element :description
11
- end
12
- end
@@ -1,11 +0,0 @@
1
- module Socialcastr
2
- class Recipient < Base
3
- element :type
4
- element :username
5
- element :avatars, :class => Socialcastr::AvatarList
6
- element :url
7
- element :name
8
- element :id
9
- element :private
10
- end
11
- end
@@ -1,8 +0,0 @@
1
- module Socialcastr
2
- class Source < Base
3
- element :url
4
- element :formal_name
5
- element :name
6
- element :id
7
- end
8
- end
@@ -1,10 +0,0 @@
1
- module Socialcastr
2
- class Stream < Base
3
- element :id
4
- element :name
5
- element :default
6
- element :last_interacted_at
7
- element :custom_stream
8
- element :group, :class => Socialcastr::Group
9
- end
10
- end
@@ -1,5 +0,0 @@
1
- module Socialcastr
2
- class Tag < Base
3
- element :name
4
- end
5
- end
@@ -1,8 +0,0 @@
1
- module Socialcastr
2
- class ThumbnailList < Base
3
- element :square45
4
- element :stream_square
5
- element :scaled480
6
- element :stream
7
- end
8
- end
@@ -1,11 +0,0 @@
1
- module Socialcastr
2
- class User < Base
3
- element :type
4
- element :terminated
5
- element :username
6
- element :avatars, :class => AvatarList
7
- element :url
8
- element :name
9
- element :id
10
- end
11
- end