socialcastr 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/socialcastr/base.rb +1 -1
- data/lib/socialcastr/message.rb +0 -2
- data/lib/socialcastr/sax/active_resource.rb +54 -51
- data/lib/socialcastr/version.rb +1 -1
- data/socialcastr.gemspec +1 -1
- data/spec/api_spec.rb +1 -1
- data/spec/base_spec.rb +2 -2
- data/spec/message_spec.rb +0 -1
- data/spec/sax/active_resource_spec.rb +108 -0
- metadata +64 -106
data/lib/socialcastr/base.rb
CHANGED
@@ -67,7 +67,7 @@ module Socialcastr
|
|
67
67
|
|
68
68
|
def method_missing(method, *args, &block)
|
69
69
|
if method.to_s =~ /=$/
|
70
|
-
@data[method_name(method.to_s.sub(/=$/,''))] =
|
70
|
+
@data[method_name(method.to_s.sub(/=$/,''))] = args.first
|
71
71
|
else
|
72
72
|
return @data[method_name(method)] unless @data[method_name(method)].nil?
|
73
73
|
end
|
data/lib/socialcastr/message.rb
CHANGED
@@ -35,9 +35,7 @@ module Socialcastr
|
|
35
35
|
|
36
36
|
|
37
37
|
def self.search(query, arguments={})
|
38
|
-
puts "searching for #{query}"
|
39
38
|
xml = api.get(collection_path + "/search", { :q => query}.merge(arguments))
|
40
|
-
puts "Got a response xml of #{xml.length} bytes"
|
41
39
|
return parse(xml)
|
42
40
|
end
|
43
41
|
end
|
@@ -1,10 +1,3 @@
|
|
1
|
-
class Boolean
|
2
|
-
def initialize(string)
|
3
|
-
return true if string == "true"
|
4
|
-
return false
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
1
|
class String
|
9
2
|
def contains_dot?
|
10
3
|
self =~ /\./
|
@@ -26,6 +19,11 @@ module Socialcastr
|
|
26
19
|
|
27
20
|
class ActiveResource < Nokogiri::XML::SAX::Document
|
28
21
|
attr_accessor :data
|
22
|
+
HASH = "hash"
|
23
|
+
ARRAY = "array"
|
24
|
+
INTEGER = "integer"
|
25
|
+
BOOLEAN = "boolean"
|
26
|
+
STRING = "string"
|
29
27
|
|
30
28
|
def initialize
|
31
29
|
@types = []
|
@@ -37,20 +35,60 @@ module Socialcastr
|
|
37
35
|
characters(s)
|
38
36
|
end
|
39
37
|
|
38
|
+
def start_element name, attrs = []
|
39
|
+
return nil_element! if name.contains_dot? # [FIXME] we can't evaluate strings inside elements like <html.title>
|
40
|
+
type = parse_attrs_and_get_type(attrs)
|
41
|
+
return if nil_element?
|
42
|
+
push_element(type)
|
43
|
+
end
|
44
|
+
|
45
|
+
def characters string
|
46
|
+
return if nil_element? || (string.all_spaces? && (container_type != STRING || container_value.nil?))
|
47
|
+
update_string_element(string)
|
48
|
+
end
|
49
|
+
|
50
|
+
def end_element name
|
51
|
+
return end_nil_element if nil_element?
|
52
|
+
|
53
|
+
(value, type) = pop_element
|
54
|
+
case type
|
55
|
+
when HASH
|
56
|
+
element = element_class(name).from_hash(value || {})
|
57
|
+
when INTEGER
|
58
|
+
element = value.to_i
|
59
|
+
when BOOLEAN
|
60
|
+
element = value == "true" ? true : false
|
61
|
+
when ARRAY
|
62
|
+
element = value || []
|
63
|
+
else
|
64
|
+
element = value
|
65
|
+
end
|
66
|
+
|
67
|
+
if container_type
|
68
|
+
add_to_container(name, element)
|
69
|
+
else # Root Node
|
70
|
+
self.data = element
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def element_class(name)
|
77
|
+
if RUBY_VERSION < '1.9'
|
78
|
+
Socialcastr.const_get(Socialcastr.to_class_name(name))
|
79
|
+
else
|
80
|
+
Socialcastr.const_get(Socialcastr.to_class_name(name), false)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
40
84
|
def container_type
|
41
|
-
@types
|
85
|
+
@types.last
|
42
86
|
end
|
43
87
|
|
44
88
|
def container_value
|
45
|
-
@values
|
89
|
+
@values.last
|
46
90
|
end
|
47
91
|
|
48
|
-
HASH = 104 # 'h'
|
49
|
-
ARRAY = 97 # 'a'
|
50
|
-
INTEGER = 105 # 'i'
|
51
|
-
BOOLEAN = 98 # 'b'
|
52
|
-
STRING = 115 # 's'
|
53
|
-
|
54
92
|
def nil_element!
|
55
93
|
@nil = true
|
56
94
|
end
|
@@ -66,7 +104,7 @@ module Socialcastr
|
|
66
104
|
def parse_attrs_and_get_type(attribute_array=[])
|
67
105
|
attributes = attribute_array.to_hash
|
68
106
|
return nil_element! if attributes["nil"]
|
69
|
-
attributes["type"] ? attributes["type"]
|
107
|
+
attributes["type"] ? attributes["type"] : HASH
|
70
108
|
end
|
71
109
|
|
72
110
|
def push_element(type)
|
@@ -91,41 +129,6 @@ module Socialcastr
|
|
91
129
|
end
|
92
130
|
end
|
93
131
|
|
94
|
-
def start_element name, attrs = []
|
95
|
-
return nil_element! if name.contains_dot? # [FIXME] we can't evaluate strings inside elements like <html.title>
|
96
|
-
type = parse_attrs_and_get_type(attrs)
|
97
|
-
return if nil_element?
|
98
|
-
push_element(type)
|
99
|
-
end
|
100
|
-
|
101
|
-
def characters string
|
102
|
-
return if nil_element? || (string.all_spaces? && (container_type != STRING || container_value.nil?))
|
103
|
-
update_string_element(string)
|
104
|
-
end
|
105
|
-
|
106
|
-
def end_element name
|
107
|
-
return end_nil_element if nil_element?
|
108
|
-
|
109
|
-
(value, type) = pop_element
|
110
|
-
case type
|
111
|
-
when HASH
|
112
|
-
element = Socialcastr.const_get(Socialcastr.to_class_name(name), false).from_hash(value || {})
|
113
|
-
when INTEGER
|
114
|
-
element = value.to_i
|
115
|
-
when BOOLEAN
|
116
|
-
element = Boolean.new(value)
|
117
|
-
when ARRAY
|
118
|
-
element = value || []
|
119
|
-
else
|
120
|
-
element = value
|
121
|
-
end
|
122
|
-
|
123
|
-
if container_type
|
124
|
-
add_to_container(name, element)
|
125
|
-
else # Root Node
|
126
|
-
self.data = element
|
127
|
-
end
|
128
|
-
end
|
129
132
|
end
|
130
133
|
end
|
131
134
|
end
|
data/lib/socialcastr/version.rb
CHANGED
data/socialcastr.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.add_development_dependency('rspec', '~> 2.5')
|
7
7
|
s.add_development_dependency('yard')
|
8
8
|
s.add_development_dependency('artifice')
|
9
|
-
s.add_runtime_dependency('nokogiri', '1.4.4')
|
9
|
+
s.add_runtime_dependency('nokogiri', '>= 1.4.4')
|
10
10
|
s.authors = ["Riccardo Cambiassi"]
|
11
11
|
s.description = %q{A Ruby wrapper for the Socialcast REST API}
|
12
12
|
s.post_install_message =<<eos
|
data/spec/api_spec.rb
CHANGED
@@ -142,7 +142,7 @@ describe Socialcastr::API do
|
|
142
142
|
@https.class.should == Net::HTTP
|
143
143
|
end
|
144
144
|
it "should use ssl" do
|
145
|
-
@https.use_ssl
|
145
|
+
@https.use_ssl?.should be_true
|
146
146
|
end
|
147
147
|
it "should not verify SSL" do
|
148
148
|
@https.verify_mode.should == OpenSSL::SSL::VERIFY_NONE
|
data/spec/base_spec.rb
CHANGED
@@ -117,7 +117,7 @@ describe Socialcastr::Base do
|
|
117
117
|
|
118
118
|
context 'after modifying one attribute' do
|
119
119
|
before :each do
|
120
|
-
@message.title =
|
120
|
+
@message.title = "new title"
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'the attribute should be changed' do
|
@@ -162,7 +162,7 @@ describe Socialcastr::Base do
|
|
162
162
|
|
163
163
|
context 'last or find(:last)' do
|
164
164
|
before :each do
|
165
|
-
fake_socialcast_api_for(:
|
165
|
+
fake_socialcast_api_for(:messages) do
|
166
166
|
@message = Socialcastr::Message.last
|
167
167
|
end
|
168
168
|
end
|
data/spec/message_spec.rb
CHANGED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Socialcastr::SAX::ActiveResource do
|
4
|
+
describe "#parse" do
|
5
|
+
before do
|
6
|
+
@active_resource = Socialcastr::SAX::ActiveResource.new
|
7
|
+
@parser = Nokogiri::XML::SAX::Parser.new(@active_resource)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "an empty document with a root 'message' element" do
|
11
|
+
it "should return a Message object" do
|
12
|
+
xml = "<message></message>"
|
13
|
+
@parser.parse(xml)
|
14
|
+
@active_resource.data.class.should == Socialcastr::Message
|
15
|
+
end
|
16
|
+
end
|
17
|
+
context "a document with a nil element" do
|
18
|
+
it "should make the nil element accessible" do
|
19
|
+
xml = "<message><rating nil=\"true\"></rating></message>"
|
20
|
+
@parser.parse(xml)
|
21
|
+
@active_resource.data.rating.should be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "a document with a string element" do
|
26
|
+
it "should make the element accessible as a string" do
|
27
|
+
xml = "<message><title>Hello World!</title></message>"
|
28
|
+
@parser.parse(xml)
|
29
|
+
@active_resource.data.title.class.should == String
|
30
|
+
@active_resource.data.title.should == "Hello World!"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "a document with a true boolean element" do
|
35
|
+
it "should make the element accessible as a boolean" do
|
36
|
+
xml = "<message><ratable type=\"boolean\">true</ratable></message>"
|
37
|
+
@parser.parse(xml)
|
38
|
+
@active_resource.data.ratable.should be_true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "a document with a false boolean element" do
|
43
|
+
it "should make the element accessible as a boolean" do
|
44
|
+
xml = "<message><ratable type=\"boolean\">false</ratable></message>"
|
45
|
+
@parser.parse(xml)
|
46
|
+
@active_resource.data.ratable.should be_false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "a document with an array of 2 string elements" do
|
51
|
+
before do
|
52
|
+
xml = "<message><tags type=\"array\"><tag>first</tag><tag>second</tag></tags></message>"
|
53
|
+
@parser.parse(xml)
|
54
|
+
end
|
55
|
+
it "should make the array accessible through the collection name" do
|
56
|
+
@active_resource.data.tags.class.should == Array
|
57
|
+
end
|
58
|
+
it "should have an array containing 2 elements" do
|
59
|
+
@active_resource.data.tags.size.should == 2
|
60
|
+
end
|
61
|
+
it "should have an array of objects of class string" do
|
62
|
+
@active_resource.data.tags.first.class.should == String
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "a document with an array of 2 complex elements" do
|
67
|
+
before do
|
68
|
+
xml = "<message><tags type=\"array\"><tag><name>first</name></tag><tag><name>second</name></tag></tags></message>"
|
69
|
+
@parser.parse(xml)
|
70
|
+
end
|
71
|
+
it "should make the array accessible through the c ollection name" do
|
72
|
+
@active_resource.data.tags.class.should == Array
|
73
|
+
end
|
74
|
+
it "should have an array containing 2 elements" do
|
75
|
+
@active_resource.data.tags.size.should == 2
|
76
|
+
end
|
77
|
+
it "should have an array of objects of class derived from the element name" do
|
78
|
+
@active_resource.data.tags.first.class.should == Socialcastr::Tag
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "a document with an array as the root element" do
|
83
|
+
before do
|
84
|
+
xml = "<messages type=\"array\"><msg>hello</msg><msg>world</msg></messages>"
|
85
|
+
@parser.parse(xml)
|
86
|
+
end
|
87
|
+
it "should return an array" do
|
88
|
+
@active_resource.data.class.should == Array
|
89
|
+
end
|
90
|
+
it "should grant access to each element" do
|
91
|
+
@active_resource.data.first.should == "hello"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "a document with a complex element" do
|
96
|
+
before do
|
97
|
+
xml = "<message><user><username>johndoe</username><name>John Doe</name></user></message>"
|
98
|
+
@parser.parse(xml)
|
99
|
+
end
|
100
|
+
it "should grant access to the inside element as an object of class derived from the element name" do
|
101
|
+
@active_resource.data.user.class.should == Socialcastr::User
|
102
|
+
end
|
103
|
+
it "should grant access to nested elements as methods of the parent class" do
|
104
|
+
@active_resource.data.user.username.should == "johndoe"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
metadata
CHANGED
@@ -1,106 +1,79 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: socialcastr
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 4
|
10
|
-
version: 0.2.4
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Riccardo Cambiassi
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-07-19 00:00:00.000000000 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
21
16
|
name: rake
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirement: &2153287440 !ruby/object:Gem::Requirement
|
24
18
|
none: false
|
25
|
-
requirements:
|
19
|
+
requirements:
|
26
20
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 8
|
32
|
-
version: "0.8"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.8'
|
33
23
|
type: :development
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rspec
|
37
24
|
prerelease: false
|
38
|
-
|
25
|
+
version_requirements: *2153287440
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: &2153315340 !ruby/object:Gem::Requirement
|
39
29
|
none: false
|
40
|
-
requirements:
|
30
|
+
requirements:
|
41
31
|
- - ~>
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 2
|
46
|
-
- 5
|
47
|
-
version: "2.5"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.5'
|
48
34
|
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: yard
|
52
35
|
prerelease: false
|
53
|
-
|
36
|
+
version_requirements: *2153315340
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: yard
|
39
|
+
requirement: &2153314960 !ruby/object:Gem::Requirement
|
54
40
|
none: false
|
55
|
-
requirements:
|
56
|
-
- -
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
segments:
|
60
|
-
- 0
|
61
|
-
version: "0"
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
62
45
|
type: :development
|
63
|
-
version_requirements: *id003
|
64
|
-
- !ruby/object:Gem::Dependency
|
65
|
-
name: artifice
|
66
46
|
prerelease: false
|
67
|
-
|
47
|
+
version_requirements: *2153314960
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: artifice
|
50
|
+
requirement: &2153314500 !ruby/object:Gem::Requirement
|
68
51
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
segments:
|
74
|
-
- 0
|
75
|
-
version: "0"
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
76
56
|
type: :development
|
77
|
-
version_requirements: *id004
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: nokogiri
|
80
57
|
prerelease: false
|
81
|
-
|
58
|
+
version_requirements: *2153314500
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: nokogiri
|
61
|
+
requirement: &2153314000 !ruby/object:Gem::Requirement
|
82
62
|
none: false
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
hash: 15
|
87
|
-
segments:
|
88
|
-
- 1
|
89
|
-
- 4
|
90
|
-
- 4
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
91
66
|
version: 1.4.4
|
92
67
|
type: :runtime
|
93
|
-
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *2153314000
|
94
70
|
description: A Ruby wrapper for the Socialcast REST API
|
95
|
-
email:
|
71
|
+
email:
|
96
72
|
- bru@codewitch.org
|
97
73
|
executables: []
|
98
|
-
|
99
74
|
extensions: []
|
100
|
-
|
101
75
|
extra_rdoc_files: []
|
102
|
-
|
103
|
-
files:
|
76
|
+
files:
|
104
77
|
- .gitignore
|
105
78
|
- Gemfile
|
106
79
|
- LICENSE.markdown
|
@@ -129,53 +102,37 @@ files:
|
|
129
102
|
- spec/fixtures/message.xml
|
130
103
|
- spec/fixtures/messages.xml
|
131
104
|
- spec/message_spec.rb
|
105
|
+
- spec/sax/active_resource_spec.rb
|
132
106
|
- spec/socialcastr_spec.rb
|
133
107
|
- spec/spec_helper.rb
|
108
|
+
has_rdoc: true
|
134
109
|
homepage: https://github.com/bru/socialcastr
|
135
110
|
licenses: []
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
Thank you for installing socialcastr
|
141
|
-
|
142
|
-
Follow @bru on Twitter for announcements, updates, and news.
|
143
|
-
https://twitter.com/bru
|
144
|
-
|
145
|
-
********************************************************************************
|
146
|
-
|
111
|
+
post_install_message: ! "********************************************************************************\n\n
|
112
|
+
\ Thank you for installing socialcastr\n\n Follow @bru on Twitter for announcements,
|
113
|
+
updates, and news.\n https://twitter.com/bru\n\n********************************************************************************\n"
|
147
114
|
rdoc_options: []
|
148
|
-
|
149
|
-
require_paths:
|
115
|
+
require_paths:
|
150
116
|
- lib
|
151
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
118
|
none: false
|
153
|
-
requirements:
|
154
|
-
- -
|
155
|
-
- !ruby/object:Gem::Version
|
156
|
-
|
157
|
-
|
158
|
-
- 0
|
159
|
-
version: "0"
|
160
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
124
|
none: false
|
162
|
-
requirements:
|
163
|
-
- -
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
hash: 23
|
166
|
-
segments:
|
167
|
-
- 1
|
168
|
-
- 3
|
169
|
-
- 6
|
125
|
+
requirements:
|
126
|
+
- - ! '>='
|
127
|
+
- !ruby/object:Gem::Version
|
170
128
|
version: 1.3.6
|
171
129
|
requirements: []
|
172
|
-
|
173
130
|
rubyforge_project: socialcastr
|
174
|
-
rubygems_version: 1.
|
131
|
+
rubygems_version: 1.6.2
|
175
132
|
signing_key:
|
176
133
|
specification_version: 3
|
177
134
|
summary: Ruby wrapper for the Socialcast API
|
178
|
-
test_files:
|
135
|
+
test_files:
|
179
136
|
- spec/api_spec.rb
|
180
137
|
- spec/base_spec.rb
|
181
138
|
- spec/comment_spec.rb
|
@@ -184,5 +141,6 @@ test_files:
|
|
184
141
|
- spec/fixtures/message.xml
|
185
142
|
- spec/fixtures/messages.xml
|
186
143
|
- spec/message_spec.rb
|
144
|
+
- spec/sax/active_resource_spec.rb
|
187
145
|
- spec/socialcastr_spec.rb
|
188
146
|
- spec/spec_helper.rb
|