needish 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/License.txt +20 -0
- data/Manifest.txt +17 -0
- data/PostInstall.txt +9 -0
- data/README.txt +102 -0
- data/Rakefile +4 -0
- data/lib/needish.rb +14 -0
- data/lib/needish/base.rb +194 -0
- data/lib/needish/easy_class_maker.rb +43 -0
- data/lib/needish/friend.rb +35 -0
- data/lib/needish/help.rb +51 -0
- data/lib/needish/need.rb +102 -0
- data/lib/needish/user.rb +29 -0
- data/lib/needish/version.rb +9 -0
- data/test/test_helper.rb +2 -0
- data/test/test_needish.rb +11 -0
- metadata +93 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Miguel Michelson Martinez
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.txt
|
6
|
+
Rakefile
|
7
|
+
lib/needish.rb
|
8
|
+
lib/needish/version.rb
|
9
|
+
lib/needish/base.rb
|
10
|
+
lib/needish/easy_class_maker.rb
|
11
|
+
lib/needish/friend.rb
|
12
|
+
lib/needish/help.rb
|
13
|
+
lib/needish/need.rb
|
14
|
+
lib/needish/user.rb
|
15
|
+
test/test_helper.rb
|
16
|
+
test/test_needish.rb
|
17
|
+
|
data/PostInstall.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
= needish
|
2
|
+
|
3
|
+
* FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This Gems provides basic methods to access the Nedish.com api
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
lists the user profile, user friends , needs and helps from a need
|
12
|
+
sends needs, helps
|
13
|
+
|
14
|
+
-problems.
|
15
|
+
no detected yet!
|
16
|
+
|
17
|
+
-todo
|
18
|
+
search methods
|
19
|
+
make friends etc..
|
20
|
+
|
21
|
+
== SYNOPSIS:
|
22
|
+
|
23
|
+
*examples
|
24
|
+
|
25
|
+
login to needish
|
26
|
+
pass to login user and pass AND apikey!! (since 0.0.2)
|
27
|
+
|
28
|
+
<pre>login = Needish::Base.new('miguelmichelson@gmail.com','********' ,'apikey2234455566')</pre>
|
29
|
+
|
30
|
+
obtain the user logged data
|
31
|
+
|
32
|
+
<pre>miguel = login.me</pre>
|
33
|
+
|
34
|
+
obtain the user id
|
35
|
+
|
36
|
+
<pre>miguel.id</pre>
|
37
|
+
|
38
|
+
obtain the user friends
|
39
|
+
|
40
|
+
<pre>login.user_friends(miguel.id)</pre>
|
41
|
+
|
42
|
+
obtain the needs
|
43
|
+
|
44
|
+
<pre>login.user_needs(me.id)</pre>
|
45
|
+
|
46
|
+
obtain the needs helps
|
47
|
+
|
48
|
+
<pre>login.helps(user_needs(me.id)[0].id)</pre>
|
49
|
+
|
50
|
+
Other methods
|
51
|
+
|
52
|
+
add need, pass subject and text
|
53
|
+
|
54
|
+
<pre>login.add_need('subject','text')</pre>
|
55
|
+
|
56
|
+
add help, pass need id and text
|
57
|
+
|
58
|
+
<pre>login.add_help(need.id,'text')</pre>
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
== REQUIREMENTS:
|
63
|
+
|
64
|
+
this gem requires hricot,
|
65
|
+
|
66
|
+
sudo gem install hpricot
|
67
|
+
|
68
|
+
|
69
|
+
== INSTALL:
|
70
|
+
|
71
|
+
to install this gem simply do :
|
72
|
+
|
73
|
+
git clone git://github.com/michelson/needish-gem.git
|
74
|
+
|
75
|
+
cd needish-gem
|
76
|
+
|
77
|
+
sudo install gem pkg/needish-0.0.1.gem
|
78
|
+
|
79
|
+
== LICENSE:
|
80
|
+
|
81
|
+
(The MIT License)
|
82
|
+
|
83
|
+
Copyright (c) 2008 FIXME full name
|
84
|
+
|
85
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
86
|
+
a copy of this software and associated documentation files (the
|
87
|
+
'Software'), to deal in the Software without restriction, including
|
88
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
89
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
90
|
+
permit persons to whom the Software is furnished to do so, subject to
|
91
|
+
the following conditions:
|
92
|
+
|
93
|
+
The above copyright notice and this permission notice shall be
|
94
|
+
included in all copies or substantial portions of the Software.
|
95
|
+
|
96
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
97
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
98
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
99
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
100
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
101
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
102
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/needish.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
%w(uri cgi net/http yaml rubygems hpricot active_support).each { |f| require f }
|
2
|
+
|
3
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
4
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
require 'needish/version'
|
9
|
+
require 'needish/easy_class_maker'
|
10
|
+
require 'needish/base'
|
11
|
+
require 'needish/user'
|
12
|
+
require 'needish/friend'
|
13
|
+
require 'needish/need'
|
14
|
+
require 'needish/help'
|
data/lib/needish/base.rb
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
# very inspired in twitter gem
|
2
|
+
# This is the base class for the needish library. It makes all the requests
|
3
|
+
# to needish, parses the xml (using hpricot) and returns ruby objects to play with.
|
4
|
+
# The private methods in this one are pretty fun. Be sure to check out users, needs and helps...
|
5
|
+
module Needish
|
6
|
+
class Untwitterable < StandardError; end
|
7
|
+
class CantConnect < Untwitterable; end
|
8
|
+
class BadResponse < Untwitterable; end
|
9
|
+
class UnknownTimeline < ArgumentError; end
|
10
|
+
|
11
|
+
class Base
|
12
|
+
# Needish's url, duh!
|
13
|
+
@@api_url = 'api.needish.com'
|
14
|
+
# Timelines exposed by the needish api
|
15
|
+
@@timelines = [:friends, :public, :user]
|
16
|
+
|
17
|
+
def self.timelines
|
18
|
+
@@timelines
|
19
|
+
end
|
20
|
+
|
21
|
+
# Initializes the configuration for making requests to needish
|
22
|
+
def initialize(email, password, apikey)
|
23
|
+
@config, @config[:email], @config[:password],@config[:apikey] = {}, email, password,"?app_key=#{apikey}"
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
#returns user data information
|
29
|
+
def me
|
30
|
+
users(request("users/authenticate.xml", :auth => true))
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns the profile of a given user,
|
34
|
+
def user_profile(id)
|
35
|
+
users(request("users/profile/#{id}.xml", :auth => true))
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns the profile of a given user, including the recent needs. The needs are ordered by descending date of creation.
|
39
|
+
def user_needs(id)
|
40
|
+
needs_data(request("users/profile/#{id}.xml", :auth => true))
|
41
|
+
end
|
42
|
+
|
43
|
+
# Returns an array of users who are in your friends list
|
44
|
+
def friends(id)
|
45
|
+
friends_data(request("users/friends/#{id}.xml", :auth => true))
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns the most active needs, ordered by descending number of recent helps.
|
49
|
+
def hot_needs
|
50
|
+
needs_generic_data(request("needs/hot.xml", :auth => true))
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns up to 100 recent public needs, ordered by descending date of creation.
|
54
|
+
def all_needs
|
55
|
+
needs_generic_data(request("needs/all.xml", :auth => true))
|
56
|
+
end
|
57
|
+
|
58
|
+
#Returns up to 100 recent needs of the authenticating user friends, ordered by descending date of creation.
|
59
|
+
def friends_needs
|
60
|
+
needs_generic_data(request("needs/friends.xml", :auth => true))
|
61
|
+
end
|
62
|
+
|
63
|
+
#Returns up to 100 recent public needs created by the given user, ordered by descending date of creation.
|
64
|
+
def needs_from_user(id)
|
65
|
+
needs_generic_data(request("needs/user/#{id}.xml", :auth => true))
|
66
|
+
end
|
67
|
+
|
68
|
+
#Returns the given need
|
69
|
+
def view_need(id)
|
70
|
+
needs_view_data(request("needs/view/#{id}.xml", :auth => true))
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns up to 100 helps for the given need, ordered by date of creation.
|
74
|
+
def helps(id)
|
75
|
+
helps_data(request("needs/helps/#{id}.xml", :auth => true))
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
# Send data
|
80
|
+
|
81
|
+
|
82
|
+
# Post a new Need for the authenticating user.
|
83
|
+
|
84
|
+
# http://api.needish.com/needs/add.format
|
85
|
+
def add_need(subject, text)
|
86
|
+
url = URI.parse("http://#{@@api_url}/needs/add.xml#{@config[:apikey]}")
|
87
|
+
req = Net::HTTP::Post.new(url.path)
|
88
|
+
|
89
|
+
req.basic_auth(@config[:email], @config[:password])
|
90
|
+
req.set_form_data({'text' => text, 'subject' => subject})
|
91
|
+
|
92
|
+
response = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
|
93
|
+
parse(response.body)
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
# Post a new Need for the authenticating user.
|
98
|
+
|
99
|
+
def add_help(id, text)
|
100
|
+
url = URI.parse("http://#{@@api_url}/helps/add/#{id}.xml#{@config[:apikey]}")
|
101
|
+
req = Net::HTTP::Post.new(url.path+@config[:apikey])
|
102
|
+
|
103
|
+
req.basic_auth(@config[:email], @config[:password])
|
104
|
+
req.set_form_data({'text' => text})
|
105
|
+
|
106
|
+
response = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
|
107
|
+
parse(response.body)
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
#to do
|
112
|
+
# twitter style
|
113
|
+
# Befriends the user specified in the ID parameter as the authenticating user.
|
114
|
+
|
115
|
+
# def create_friendship(id_or_screenname)
|
116
|
+
# users(request("friends/add/#{id_or_screenname}.xml", :auth => true)).first
|
117
|
+
#end
|
118
|
+
|
119
|
+
#def destroy_friendship(id_or_screenname)
|
120
|
+
# users(request("friends/destroy/#{id_or_screenname}.xml", :auth => true)).first
|
121
|
+
#end
|
122
|
+
|
123
|
+
#def follow(id_or_screenname)
|
124
|
+
# users(request("notifications/follow/#{id_or_screenname}.xml", :auth => true)).first
|
125
|
+
#end
|
126
|
+
|
127
|
+
#def leave(id_or_screenname)
|
128
|
+
# users(request("notifications/leave/#{id_or_screenname}.xml", :auth => true)).first
|
129
|
+
#end
|
130
|
+
|
131
|
+
|
132
|
+
private
|
133
|
+
# Converts an hpricot doc to an array of statuses
|
134
|
+
|
135
|
+
# Converts an hpricot doc to an array of ..
|
136
|
+
|
137
|
+
def users(doc)
|
138
|
+
#(doc/:user).inject([]) { |users, user| users << User.new_from_xml(user); users }
|
139
|
+
User.new_from_xml(doc)
|
140
|
+
end
|
141
|
+
|
142
|
+
def friends_data(doc)
|
143
|
+
# (doc/:user).inject([]) { |users, user| users << Friend.new_from_xml(user); users }
|
144
|
+
|
145
|
+
Friend.new_from_xml(doc)
|
146
|
+
end
|
147
|
+
|
148
|
+
def needs_data(doc)
|
149
|
+
Need.new_from_xml(doc)
|
150
|
+
end
|
151
|
+
|
152
|
+
def needs_generic_data(doc)
|
153
|
+
Need.generic_from_xml(doc)
|
154
|
+
end
|
155
|
+
def needs_view_data(doc)
|
156
|
+
Need.generic_view_from_xml(doc)
|
157
|
+
end
|
158
|
+
|
159
|
+
def helps_data(doc)
|
160
|
+
Help.new_from_xml(doc)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Calls whatever api method requested that deals with statuses
|
164
|
+
#
|
165
|
+
# ie: call(:public_timeline, :auth => false)
|
166
|
+
def call(method, options={})
|
167
|
+
options.reverse_merge!({ :auth => true, :args => {} })
|
168
|
+
path = "statuses/#{method.to_s}.xml"
|
169
|
+
path += '?' + options[:args].inject('') { |qs, h| qs += "#{h[0]}=#{h[1]}&"; qs } unless options[:args].blank?
|
170
|
+
request(path, options)
|
171
|
+
end
|
172
|
+
|
173
|
+
def request(path, options={})
|
174
|
+
options.reverse_merge!({:headers => { "User-Agent" => @config[:email] }})
|
175
|
+
begin
|
176
|
+
response = Net::HTTP.start(@@api_url, 80) do |http|
|
177
|
+
req = Net::HTTP::Get.new('/' + path+@config[:apikey], options[:headers])
|
178
|
+
req.basic_auth(@config[:email], @config[:password]) if options[:auth]
|
179
|
+
http.request(req)
|
180
|
+
end
|
181
|
+
#puts req.body
|
182
|
+
|
183
|
+
raise BadResponse unless response.message == 'OK'
|
184
|
+
parse(response.body)
|
185
|
+
rescue
|
186
|
+
raise CantConnect
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def parse(response)
|
191
|
+
Hpricot.XML(response)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# This is pretty much just a macro for creating a class that allows
|
2
|
+
# using a block to initialize stuff and to define getters and setters
|
3
|
+
# really quickly.
|
4
|
+
module Needish
|
5
|
+
module EasyClassMaker
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.extend(ClassMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
# creates the attributes class variable and creates each attribute's accessor methods
|
13
|
+
def attributes(*attrs)
|
14
|
+
@@attributes = attrs
|
15
|
+
@@attributes.each { |a| attr_accessor a }
|
16
|
+
end
|
17
|
+
|
18
|
+
# read method for attributes class variable
|
19
|
+
def self.attributes; @@attributes end
|
20
|
+
end
|
21
|
+
|
22
|
+
# allows for any class that includes this to use a block to initialize
|
23
|
+
# variables instead of assigning each one seperately
|
24
|
+
#
|
25
|
+
# Example:
|
26
|
+
#
|
27
|
+
# instead of...
|
28
|
+
#
|
29
|
+
# s = Status.new
|
30
|
+
# s.foo = 'thing'
|
31
|
+
# s.bar = 'another thing'
|
32
|
+
#
|
33
|
+
# you can ...
|
34
|
+
#
|
35
|
+
# Status.new do |s|
|
36
|
+
# s.foo = 'thing'
|
37
|
+
# s.bar = 'another thing'
|
38
|
+
# end
|
39
|
+
def initialize
|
40
|
+
yield self if block_given?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Needish
|
2
|
+
class Friend
|
3
|
+
include EasyClassMaker
|
4
|
+
|
5
|
+
attributes :id,:name,:lastname,:nickname,:pictureurl,:displayname,:biography,
|
6
|
+
:userneeds,:biography,:friendstatus
|
7
|
+
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
# Creates a new user from a piece of xml
|
12
|
+
def new_from_xml(xml)
|
13
|
+
|
14
|
+
result = []
|
15
|
+
|
16
|
+
xml.search("user").each do |user|
|
17
|
+
Friend.new do |u|
|
18
|
+
u.id = user[:id]
|
19
|
+
u.name = user[:name]
|
20
|
+
u.lastname = user[:lastname]
|
21
|
+
u.nickname = user[:nickname]
|
22
|
+
u.pictureurl = user[:pictureurl]
|
23
|
+
u.displayname = user[:displayname]
|
24
|
+
result << u
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
return result
|
30
|
+
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/needish/help.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Needish
|
2
|
+
class Help
|
3
|
+
include EasyClassMaker
|
4
|
+
|
5
|
+
attributes :id,:created,:helps,:stared,:timediff,:text,
|
6
|
+
:user_id,:user_name,:user_lastname,:user_nickname,:pictureurl,:displayname
|
7
|
+
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
# Creates a new user from a piece of xml
|
12
|
+
def new_from_xml(xml)
|
13
|
+
|
14
|
+
result = []
|
15
|
+
|
16
|
+
xml.search("help").each do |help|
|
17
|
+
|
18
|
+
Help.new do |u|
|
19
|
+
u.id = help[:id]
|
20
|
+
u.created = help[:created]
|
21
|
+
u.stared = help[:stars]
|
22
|
+
u.timediff = help[:timediff]
|
23
|
+
|
24
|
+
(help/:text).each do |text|
|
25
|
+
u.text = text.inner_html
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
(help/:user).each do |user|
|
30
|
+
u.user_id = user[:id]
|
31
|
+
u.user_name = user[:name]
|
32
|
+
u.user_lastname = user[:lastname]
|
33
|
+
u.user_nickname = user[:user_nickname]
|
34
|
+
u.pictureurl = user[:pictureurl]
|
35
|
+
u.displayname = user[:displayname]
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
result << u
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
return result
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/needish/need.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
module Needish
|
2
|
+
class Need
|
3
|
+
include EasyClassMaker
|
4
|
+
|
5
|
+
attributes :id,:created,:city,:timediff,:helps,:status,:subject,:text
|
6
|
+
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# Creates a new user from a piece of xml
|
11
|
+
def new_from_xml(xml)
|
12
|
+
|
13
|
+
result = []
|
14
|
+
|
15
|
+
xml.search("userNeeds").each do |userNeeds|
|
16
|
+
(userNeeds/:need).each do |need|
|
17
|
+
Need.new do |u|
|
18
|
+
u.id = need[:id]
|
19
|
+
u.created = need[:created]
|
20
|
+
u.city = need[:city]
|
21
|
+
u.timediff = need[:timediff]
|
22
|
+
u.status = need[:status]
|
23
|
+
(need/:subject).each do |subject|
|
24
|
+
u.subject = subject.inner_html
|
25
|
+
end
|
26
|
+
(need/:text).each do |text|
|
27
|
+
u.text = text.inner_html
|
28
|
+
end
|
29
|
+
result << u
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
return result
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
def generic_from_xml(xml)
|
41
|
+
|
42
|
+
result = []
|
43
|
+
|
44
|
+
xml.search("needs").each do |userNeeds|
|
45
|
+
(userNeeds/:need).each do |need|
|
46
|
+
Need.new do |u|
|
47
|
+
u.id = need[:id]
|
48
|
+
u.created = need[:created]
|
49
|
+
u.city = need[:city]
|
50
|
+
u.timediff = need[:timediff]
|
51
|
+
u.status = need[:status]
|
52
|
+
|
53
|
+
(need/:subject).each do |subject|
|
54
|
+
u.subject = subject.inner_html
|
55
|
+
end
|
56
|
+
(need/:text).each do |text|
|
57
|
+
u.text = text.inner_html
|
58
|
+
end
|
59
|
+
result << u
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
return result
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def generic_view_from_xml(xml)
|
68
|
+
result = []
|
69
|
+
#:help_id, :help_created, :help_stars, :help_timediff,:help_text,
|
70
|
+
# :help_user_id,:help_user_name,:help_user_nickname,:help_user_picture_url,:help_user_displayname,:help_user_text
|
71
|
+
|
72
|
+
|
73
|
+
xml.search("need").each do |need|
|
74
|
+
|
75
|
+
Need.new do |u|
|
76
|
+
u.id = need[:id]
|
77
|
+
u.created = need[:created]
|
78
|
+
u.city = need[:city]
|
79
|
+
u.timediff = need[:timediff]
|
80
|
+
u.status = need[:status]
|
81
|
+
|
82
|
+
(need/:subject).each do |subject|
|
83
|
+
u.subject = subject.inner_html
|
84
|
+
end
|
85
|
+
|
86
|
+
u.text = need.search('text').first.inner_html
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
result << u
|
92
|
+
end
|
93
|
+
end
|
94
|
+
return result[0]
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/needish/user.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Needish
|
2
|
+
class User
|
3
|
+
include EasyClassMaker
|
4
|
+
|
5
|
+
attributes :id,:name,:lastname,:nickname,:pictureurl,:displayname,:biography,
|
6
|
+
:userneeds
|
7
|
+
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# Creates a new user from a piece of xml
|
11
|
+
def new_from_xml(xml)
|
12
|
+
User.new do |u|
|
13
|
+
|
14
|
+
|
15
|
+
u.id = xml.search("user").first[:id]
|
16
|
+
u.name = xml.search("user").first[:name]
|
17
|
+
u.lastname = xml.search("user").first[:lastname]
|
18
|
+
u.nickname = xml.search("user").first[:nickname]
|
19
|
+
u.pictureurl = xml.search("user").first[:pictureurl]
|
20
|
+
u.displayname = xml.search("user").first[:displayname]
|
21
|
+
u.biography = xml.search('biobraphy').inner_html
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: needish
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Miguel Michelson Martinez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-07-07 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.7.0
|
24
|
+
version:
|
25
|
+
description: This gem provides methods to access the needish.com api
|
26
|
+
email:
|
27
|
+
- miguelmichelson@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- License.txt
|
35
|
+
- Manifest.txt
|
36
|
+
- PostInstall.txt
|
37
|
+
- README.txt
|
38
|
+
files:
|
39
|
+
- History.txt
|
40
|
+
- License.txt
|
41
|
+
- Manifest.txt
|
42
|
+
- PostInstall.txt
|
43
|
+
- README.txt
|
44
|
+
- Rakefile
|
45
|
+
- lib/needish.rb
|
46
|
+
- lib/needish/version.rb
|
47
|
+
- lib/needish/base.rb
|
48
|
+
- lib/needish/easy_class_maker.rb
|
49
|
+
- lib/needish/friend.rb
|
50
|
+
- lib/needish/help.rb
|
51
|
+
- lib/needish/need.rb
|
52
|
+
- lib/needish/user.rb
|
53
|
+
- test/test_helper.rb
|
54
|
+
- test/test_needish.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://needish-gem.rubyforge.org
|
57
|
+
post_install_message: |+
|
58
|
+
Instalation Success!!
|
59
|
+
|
60
|
+
For more information on needish gem, see http://animalita.cl/needish-gem
|
61
|
+
|
62
|
+
cheers!
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
rdoc_options:
|
68
|
+
- --main
|
69
|
+
- README.txt
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: "0"
|
77
|
+
version:
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project: needish-gem
|
87
|
+
rubygems_version: 1.2.0
|
88
|
+
signing_key:
|
89
|
+
specification_version: 2
|
90
|
+
summary: This gem provides methods to access the needish.com api
|
91
|
+
test_files:
|
92
|
+
- test/test_helper.rb
|
93
|
+
- test/test_needish.rb
|