michelson-needish 0.0.9

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/History.txt ADDED
@@ -0,0 +1,24 @@
1
+ == 0.0.9 2008-11-08
2
+
3
+ * 1 major enhancement:
4
+ * refactoring request methods
5
+ *now it returns the response in xml when a need or helps is sended
6
+ * refactoring CDATA responses
7
+ *cleaning CDATA from xml from some html text responses
8
+
9
+ == 0.0.3 2008-05-11
10
+
11
+ * 1 major enhancement:
12
+ * new methods in base
13
+ *new methods in base.rb, helped , tag(), and search()
14
+
15
+ == 0.0.2 2008-05-07
16
+
17
+ * 1 major enhancement:
18
+ * @@apikey desapears
19
+ *The apikey passes to the method initialize, now is not a global variable, (security issues)
20
+
21
+ == 0.0.1 2008-05-07
22
+
23
+ * 1 major enhancement:
24
+ * Initial release
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,19 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.txt
6
+ Rakefile
7
+ bin/needish
8
+ lib/needish.rb
9
+ lib/needish/version.rb
10
+ lib/needish/base.rb
11
+ lib/needish/easy_class_maker.rb
12
+ lib/needish/friend.rb
13
+ lib/needish/help.rb
14
+ lib/needish/need.rb
15
+ lib/needish/user.rb
16
+ lib/needish/command.rb
17
+ test/test_helper.rb
18
+ test/test_needish.rb
19
+
data/PostInstall.txt ADDED
@@ -0,0 +1,9 @@
1
+ Instalation Success!!
2
+
3
+ For more information on needish gem, see http://animalita.cl/needish-gem
4
+
5
+ cheers!
6
+
7
+
8
+
9
+
data/README.txt ADDED
@@ -0,0 +1,110 @@
1
+ = needish
2
+
3
+ * FIX (url)
4
+ #rake debug_gem > needish.gemspec
5
+
6
+ == DESCRIPTION:
7
+
8
+ This Gems provides basic methods to access the Nedish.com api
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ lists the user profile, user friends , needs and helps from a need
13
+ sends needs, helps
14
+
15
+ -todo
16
+ search methods
17
+ make friends etc..
18
+
19
+ == SYNOPSIS:
20
+
21
+ *examples
22
+
23
+ login to needish
24
+ pass to login user and pass AND apikey!! (since 0.0.2)
25
+
26
+ <pre>login = Needish::Base.new('miguelmichelson(at)gmail.com','********' ,'apikey2234455566')</pre>
27
+
28
+ obtain the user logged data
29
+
30
+ <pre>miguel = login.me</pre>
31
+
32
+ obtain the user id
33
+
34
+ <pre>miguel.id</pre>
35
+
36
+ obtain the user friends
37
+
38
+ <pre>login.user_friends(miguel.id)</pre>
39
+
40
+ obtain the needs
41
+
42
+ <pre>login.user_needs(me.id)</pre>
43
+
44
+ obtain the needs helps
45
+
46
+ <pre>login.helps(user_needs(me.id)[0].id)</pre>
47
+
48
+ Other methods
49
+
50
+ add need, pass subject and text
51
+
52
+ <pre>login.add_need('subject','text')</pre>
53
+
54
+ add help, pass need id and text
55
+
56
+ <pre>login.add_help(need.id,'text')</pre>
57
+
58
+ new methods
59
+
60
+ helped needs
61
+ <pre> login.helped </pre>
62
+
63
+ search by tag
64
+ <pre> login.tag("tag") </pre>
65
+
66
+ simple search
67
+ <pre> login.search("term") </pre>
68
+
69
+
70
+ == REQUIREMENTS:
71
+
72
+ this gem requires hricot,
73
+
74
+ sudo gem install hpricot
75
+
76
+
77
+ == INSTALL:
78
+
79
+ to install this gem simply do :
80
+
81
+ git clone git://github.com/michelson/needish-gem.git
82
+
83
+ cd needish-gem
84
+
85
+ sudo gem install pkg/needish-0.0.1.gem
86
+
87
+ == LICENSE:
88
+
89
+ (The MIT License)
90
+
91
+ Copyright (c) 2008 FIXME Miguel Michelson Martinez
92
+
93
+ Permission is hereby granted, free of charge, to any person obtaining
94
+ a copy of this software and associated documentation files (the
95
+ 'Software'), to deal in the Software without restriction, including
96
+ without limitation the rights to use, copy, modify, merge, publish,
97
+ distribute, sublicense, and/or sell copies of the Software, and to
98
+ permit persons to whom the Software is furnished to do so, subject to
99
+ the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be
102
+ included in all copies or substantial portions of the Software.
103
+
104
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
105
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
106
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
107
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
108
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
109
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
110
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/bin/needish ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2008-7-11.
4
+ # Copyright (c) 2008. All rights reserved.
5
+
6
+ begin
7
+ require 'rubygems'
8
+ require 'needish'
9
+ #require 'needish/command'
10
+
11
+ rescue LoadError
12
+ # no rubygems to load, so we fail silently
13
+ end
14
+
15
+ require 'optparse'
16
+
17
+ # NOTE: the option -p/--path= is given as an example, and should probably be replaced in your application.
18
+
19
+ OPTIONS = {
20
+ :path => '~'
21
+ }
22
+ MANDATORY_OPTIONS = %w( )
23
+
24
+ parser = OptionParser.new do |opts|
25
+ opts.banner = <<BANNER
26
+ This application is wonderful because...
27
+
28
+ Usage: #{File.basename($0)} [options]
29
+
30
+ Options are:
31
+ BANNER
32
+ opts.separator ""
33
+ opts.on("-p", "--path=PATH", String,
34
+ "The root path for selecting files",
35
+ "Default: ~") { |OPTIONS[:path]| }
36
+ opts.on("-h", "--help",
37
+ "Show this help message.") { puts opts; exit }
38
+ opts.parse!(ARGV)
39
+
40
+ if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
41
+ puts opts; exit
42
+ end
43
+ end
44
+
45
+ path = OPTIONS[:path]
46
+
47
+ # do stuff
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'
@@ -0,0 +1,213 @@
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 UnNeedishable < StandardError; end
7
+ class CantConnect < UnNeedishable; end
8
+ class BadResponse < UnNeedishable; 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
+ #Returns up to 100 recent needs helped by the authenticating user, ordered by descending date of creation of the need. def helped(id)
79
+ def helped
80
+ needs_generic_data(request("needs/helped.xml", :auth => true))
81
+ end
82
+
83
+ #Returns up to 100 recent needs matching the terms sent, ordered by descending date of creation.
84
+ def tag(tag)
85
+ needs_generic_data(request("needs/tag/#{tag}.xml", :auth => true))
86
+ end
87
+
88
+ def search(term)
89
+ needs_generic_data(request("needs/search/#{term}.xml", :auth => true))
90
+ end
91
+
92
+
93
+ #Send data
94
+ # Post a new Need for the authenticating user
95
+ # http://api.needish.com/needs/add.format
96
+ def add_need(subject, text)
97
+ url = URI.parse("http://#{@@api_url}/needs/add.xml#{@config[:apikey]}")
98
+ req = Net::HTTP::Post.new(url.path+@config[:apikey])
99
+
100
+ req.basic_auth(@config[:email], @config[:password])
101
+ req.set_form_data({'text'=>text, 'subject'=>subject})
102
+
103
+ res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
104
+ # puts req
105
+ ## puts url.path
106
+ # puts res
107
+ needs_view_data(parse(res.body))
108
+
109
+
110
+
111
+
112
+
113
+
114
+ end
115
+
116
+ # Post a new Need for the authenticating user.
117
+
118
+ def add_help(id, text)
119
+ url = URI.parse("http://#{@@api_url}/helps/add/#{id}.xml#{@config[:apikey]}")
120
+ req = Net::HTTP::Post.new(url.path+@config[:apikey])
121
+
122
+ req.basic_auth(@config[:email], @config[:password])
123
+ req.set_form_data({'text' => text})
124
+
125
+ response = Net::HTTP.new(url.host).start { |http| http.request(req) }
126
+ parse(response.body)
127
+
128
+ end
129
+
130
+ #to do
131
+ # twitter style
132
+ # Befriends the user specified in the ID parameter as the authenticating user.
133
+
134
+ # def create_friendship(id_or_screenname)
135
+ # users(request("friends/add/#{id_or_screenname}.xml", :auth => true)).first
136
+ #end
137
+
138
+ #def destroy_friendship(id_or_screenname)
139
+ # users(request("friends/destroy/#{id_or_screenname}.xml", :auth => true)).first
140
+ #end
141
+
142
+ #def follow(id_or_screenname)
143
+ # users(request("notifications/follow/#{id_or_screenname}.xml", :auth => true)).first
144
+ #end
145
+
146
+ #def leave(id_or_screenname)
147
+ # users(request("notifications/leave/#{id_or_screenname}.xml", :auth => true)).first
148
+ #end
149
+
150
+
151
+ private
152
+ # Converts an hpricot doc to an array of statuses
153
+
154
+ # Converts an hpricot doc to an array of ..
155
+
156
+ def users(doc)
157
+ #(doc/:user).inject([]) { |users, user| users << User.new_from_xml(user); users }
158
+ User.new_from_xml(doc)
159
+ end
160
+
161
+ def friends_data(doc)
162
+ # (doc/:user).inject([]) { |users, user| users << Friend.new_from_xml(user); users }
163
+
164
+ Friend.new_from_xml(doc)
165
+ end
166
+
167
+ def needs_data(doc)
168
+ Need.new_from_xml(doc)
169
+ end
170
+
171
+ def needs_generic_data(doc)
172
+ Need.generic_from_xml(doc)
173
+ end
174
+ def needs_view_data(doc)
175
+ Need.generic_view_from_xml(doc)
176
+ end
177
+
178
+ def helps_data(doc)
179
+ Help.new_from_xml(doc)
180
+ end
181
+
182
+ # Calls whatever api method requested that deals with statuses
183
+ #
184
+ # ie: call(:public_timeline, :auth => false)
185
+ def call(method, options={})
186
+ options.reverse_merge!({ :auth => true, :args => {} })
187
+ path = "statuses/#{method.to_s}.xml"
188
+ path += '?' + options[:args].inject('') { |qs, h| qs += "#{h[0]}=#{h[1]}&"; qs } unless options[:args].blank?
189
+ request(path, options)
190
+ end
191
+
192
+ def request(path, options={})
193
+ options.reverse_merge!({:headers => { "User-Agent" => @config[:email] }})
194
+ begin
195
+ response = Net::HTTP.start(@@api_url, 80) do |http|
196
+ req = Net::HTTP::Get.new('/' + path+@config[:apikey], options[:headers])
197
+ req.basic_auth(@config[:email], @config[:password]) if options[:auth]
198
+ http.request(req)
199
+ end
200
+ #puts req.body
201
+
202
+ raise BadResponse unless response.message == 'OK'
203
+ parse(response.body)
204
+ rescue
205
+ raise CantConnect
206
+ end
207
+ end
208
+
209
+ def parse(response)
210
+ Hpricot.XML(response)
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,249 @@
1
+ # The command class is used for the command line interface.
2
+ # It is only used and included in the bin/twitter file.
3
+ module Twitter
4
+ class Command
5
+ @@commands = [:post, :timeline, :friends, :friend, :followers, :follower, :featured, :important, :follow, :leave, :d]
6
+
7
+ @@template = <<EOF
8
+ # .twitter
9
+ #
10
+ # Please fill in fields like this:
11
+ #
12
+ # email: bla@bla.com
13
+ # password: secret
14
+ #
15
+ email:
16
+ password:
17
+ EOF
18
+
19
+ class << self
20
+ def process!
21
+ command = ARGV.shift
22
+
23
+ if !command.nil? && @@commands.include?(command.intern)
24
+ send(command)
25
+ else
26
+ puts "\nUsage: needish <command> [options]\n\nAvailable Commands:"
27
+ Needish::Command.commands.each do |c|
28
+ puts " - #{c}"
29
+ end
30
+ end
31
+ end
32
+
33
+ def commands
34
+ @@commands
35
+ end
36
+
37
+ # Posts an updated status to twitter
38
+ def post
39
+ config = create_or_find_config
40
+
41
+ if ARGV.size == 0
42
+ puts %(\n You didn't enter a message to post.\n\n Usage: twitter post "You're fabulous message"\n)
43
+ exit(0)
44
+ end
45
+
46
+ post = ARGV.shift
47
+ print "\nSending needish update"
48
+ finished = false
49
+ status = nil
50
+ progress_thread = Thread.new { until finished; print "."; $stdout.flush; sleep 0.5; end; }
51
+ post_thread = Thread.new(binding()) { |b|
52
+ status = Needish::Base.new(config['email'], config['password']).post(post)
53
+ finished = true
54
+ }
55
+ post_thread.join
56
+ progress_thread.join
57
+ puts " OK!"
58
+ puts "Got it! New needish created at: #{status.created_at}\n"
59
+ end
60
+
61
+ # Shows status, time and user for the specified timeline
62
+ def timeline
63
+ config = create_or_find_config
64
+
65
+ timeline = :friends
66
+ timeline = ARGV.shift.intern if ARGV.size > 0 && Twitter::Base.timelines.include?(ARGV[0].intern)
67
+
68
+ puts
69
+ Twitter::Base.new(config['email'], config['password']).timeline(timeline).each do |s|
70
+ puts "#{s.text}\n-- #{s.user.name} at #{s.created_at}"
71
+ puts
72
+ end
73
+ end
74
+
75
+ def friends
76
+ config = create_or_find_config
77
+
78
+ puts
79
+ Twitter::Base.new(config['email'], config['password']).friends.each do |u|
80
+ puts "#{u.name} (#{u.screen_name})"
81
+ puts "#{u.status.text} at #{u.status.created_at}" unless u.status.nil?
82
+ end
83
+ end
84
+
85
+ # Shows last updated status and time for a friend
86
+ # Needs a screen name
87
+ def friend
88
+ config = create_or_find_config
89
+
90
+ if ARGV.size == 0
91
+ puts %(\n You forgot to enter a screen name.\n\n Usage: twitter friend jnunemaker\n)
92
+ exit(0)
93
+ end
94
+
95
+ screen_name = ARGV.shift
96
+
97
+ puts
98
+ found = false
99
+ Twitter::Base.new(config['email'], config['password']).friends.each do |u|
100
+ if u.screen_name == screen_name
101
+ puts "#{u.name} #{u.screen_name}"
102
+ puts "#{u.status.text} at #{u.status.created_at}" unless u.status.nil?
103
+ found = true
104
+ end
105
+ end
106
+
107
+ puts "Sorry couldn't find a friend of yours with #{screen_name} as a screen name" unless found
108
+ end
109
+
110
+ # Shows all followers and their last updated status
111
+ def followers
112
+ config = create_or_find_config
113
+
114
+ puts
115
+ Twitter::Base.new(config['email'], config['password']).followers.each do |u|
116
+ puts "#{u.name} (#{u.screen_name})"
117
+ puts "#{u.status.text} at #{u.status.created_at}" unless u.status.nil?
118
+ end
119
+ end
120
+
121
+ # Shows last updated status and time for a follower
122
+ # Needs a screen name
123
+ def follower
124
+ config = create_or_find_config
125
+
126
+ if ARGV.size == 0
127
+ puts %(\n You forgot to enter a screen name.\n\n Usage: twitter follower jnunemaker\n)
128
+ exit(0)
129
+ end
130
+
131
+ screen_name = ARGV.shift
132
+
133
+ puts
134
+ found = false
135
+ Twitter::Base.new(config['email'], config['password']).followers.each do |u|
136
+ if u.screen_name == screen_name
137
+ puts "#{u.name} (#{u.screen_name})"
138
+ puts "#{u.status.text} at #{u.status.created_at}" unless u.status.nil?
139
+ found = true
140
+ end
141
+ end
142
+
143
+ puts "Sorry couldn't find a follower of yours with #{screen_name} as a screen name" unless found
144
+ end
145
+
146
+ def featured
147
+ puts
148
+ puts 'This is all implemented, just waiting for twitter to get the api call working'
149
+ config = create_or_find_config
150
+
151
+ puts
152
+ Twitter::Base.new(config['email'], config['password']).featured.each do |u|
153
+ puts "#{u.name} last updated #{u.status.created_at}\n-- #{u.status.text}"
154
+ puts
155
+ end
156
+ end
157
+
158
+ def important
159
+ config = create_or_find_config
160
+
161
+ puts
162
+ if config['important'].nil?
163
+ puts "You have not listed your most important twitter buddies in your config file.\nYou can add important twitterers by adding the following to your config file:\nimportant:\n- jnunemaker\n- frankfurter"
164
+ else
165
+ Twitter::Base.new(config['email'], config['password']).timeline(:friends).each do |s|
166
+ if config['important'].include?(s.user.screen_name)
167
+ puts "#{s.text}\n-- #{s.user.name} at #{s.created_at}"
168
+ puts
169
+ end
170
+ end
171
+ end
172
+ end
173
+
174
+ def follow
175
+ config = create_or_find_config
176
+
177
+ if ARGV.size == 0
178
+ puts %(\n You forgot to enter a screen name or id to follow.\n\n Usage: twitter follow jnunemaker\n)
179
+ exit(0)
180
+ end
181
+
182
+ screen_name = ARGV.shift
183
+
184
+ puts
185
+ found = false
186
+ begin
187
+ Twitter::Base.new(config['email'], config['password']).follow(screen_name)
188
+ puts "You are now following notifications for #{screen_name}."
189
+ rescue
190
+ puts "FAIL: Somethin went wrong. Sorry."
191
+ end
192
+ end
193
+
194
+ def leave
195
+ config = create_or_find_config
196
+
197
+ if ARGV.size == 0
198
+ puts %(\n You forgot to enter a screen name or id to leave.\n\n Usage: twitter leave jnunemaker\n)
199
+ exit(0)
200
+ end
201
+
202
+ screen_name = ARGV.shift
203
+
204
+ puts
205
+ found = false
206
+ begin
207
+ Twitter::Base.new(config['email'], config['password']).leave(screen_name)
208
+ puts "You are no longer following notifications for #{screen_name}."
209
+ rescue
210
+ puts "FAIL: Somethin went wrong. Sorry."
211
+ end
212
+ end
213
+
214
+ # Posts a direct message to twitter
215
+ def d
216
+ config = create_or_find_config
217
+ if ARGV.size != 2
218
+ puts %(\n You didn't do it right.\n\n Usage: twitter d jnunemaker "You're fabulous message"\n)
219
+ exit(0)
220
+ end
221
+
222
+ user = ARGV.shift
223
+ post = ARGV.shift
224
+
225
+ status = Twitter::Base.new(config['email'], config['password']).d(user, post)
226
+ puts "\nDirect message sent to #{user}.\n"
227
+ end
228
+
229
+ private
230
+ # Checks for the config, creates it if not found
231
+ def create_or_find_config
232
+ home = ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']
233
+ begin
234
+ config = YAML::load open(home + "/.needish")
235
+ rescue
236
+ open(home + '/.twitter','w').write(@@template)
237
+ config = YAML::load open(home + "/.needish")
238
+ end
239
+
240
+ if config['email'] == nil or config['password'] == nil
241
+ puts "Please edit ~/.twitter to include your twitter email and password\nTextmate users: mate ~/.twitter"
242
+ exit(0)
243
+ end
244
+
245
+ config
246
+ end
247
+ end
248
+ end
249
+ 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
@@ -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 = Time.at(help[:created].to_i)
21
+ u.stared = help[:stars]
22
+ u.timediff = help[:timediff]
23
+
24
+ (help/:text).each do |text|
25
+ u.text = text.inner_html.gsub!(/\<\!\[CDATA\[(.*)\]\]\>/m, '\1')
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
@@ -0,0 +1,127 @@
1
+ module Needish
2
+ class Need
3
+ include EasyClassMaker
4
+
5
+ attributes :id,:created,:city,:timediff,:helps,:status,:subject,:text,
6
+ :user_id,:user_name,:user_lastname,:user_nickname,:pictureurl,:displayname,:attachments,:biography,
7
+ :attachment_id, :attachment_fileurl,:attachment_type,:attachment_actualurl,:attachment_name
8
+
9
+
10
+
11
+ class << self
12
+
13
+ # Creates a new user from a piece of xml
14
+ def new_from_xml(xml)
15
+
16
+ result = []
17
+
18
+ xml.search("userNeeds").each do |userNeeds|
19
+ (userNeeds/:need).each do |need|
20
+ Need.new do |u|
21
+ u.id = need[:id]
22
+ u.created = Time.at(need[:created].to_i)
23
+ u.city = need[:city]
24
+ u.timediff = need[:timediff]
25
+ u.status = need[:status]
26
+ (need/:subject).each do |subject|
27
+ u.subject = subject.inner_html.gsub!(/\<\!\[CDATA\[(.*)\]\]\>/m, '\1')
28
+ end
29
+ (need/:text).each do |text|
30
+ u.text = text.inner_html.gsub!(/\<\!\[CDATA\[(.*)\]\]\>/m, '\1')
31
+ end
32
+ result << u
33
+ end
34
+ end
35
+ end
36
+ return result
37
+ end
38
+
39
+
40
+
41
+
42
+
43
+ def generic_from_xml(xml)
44
+
45
+ result = []
46
+
47
+ xml.search("needs").each do |userNeeds|
48
+ (userNeeds/:need).each do |need|
49
+ Need.new do |u|
50
+ u.id = need[:id]
51
+ u.created = Time.at(need[:created].to_i)
52
+ u.city = need[:city]
53
+ u.timediff = need[:timediff]
54
+ u.status = need[:status]
55
+
56
+
57
+
58
+ (need/:subject).each do |subject|
59
+ u.subject = subject.inner_html.gsub!(/\<\!\[CDATA\[(.*)\]\]\>/m, '\1')
60
+ end
61
+ (need/:text).each do |text|
62
+ u.text = text.inner_html.gsub!(/\<\!\[CDATA\[(.*)\]\]\>/m, '\1')
63
+ end
64
+
65
+
66
+ #si hay attachment
67
+ if(need/:attachment)
68
+ (need/:attachment).each do |attch|
69
+ u.attachment_id = attch[:id]
70
+ u.attachment_fileurl = attch[:fileurl]
71
+ u.attachment_type = attch[:type]
72
+ u.attachment_actualurl = attch[:actualurl]
73
+ u.attachment_name = (attch/:name).inner_html.gsub!(/\<\!\[CDATA\[(.*)\]\]\>/m, '\1')
74
+ end
75
+ end
76
+
77
+ #cargamos al user para helped si existe
78
+ if(need/:user)
79
+ (need/:user).each do |user|
80
+ u.user_id = user[:id]
81
+ u.user_name = user[:name]
82
+ u.user_lastname = user[:lastname]
83
+ u.pictureurl = user[:pictureurl]
84
+ u.user_nickname = user[:user_nickname]
85
+ u.biography = (user/:biography).inner_html.gsub!(/\<\!\[CDATA\[(.*)\]\]\>/m, '\1')
86
+ # u.attachments = user[:attachments]
87
+ end
88
+ end
89
+
90
+ result << u
91
+ end
92
+ end
93
+ end
94
+ return result
95
+ end
96
+
97
+
98
+ def generic_view_from_xml(xml)
99
+ result = []
100
+
101
+ xml.search("need").each do |need|
102
+
103
+ Need.new do |u|
104
+ u.id = need[:id]
105
+ u.created = Time.at(need[:created].to_i)
106
+ u.city = need[:city]
107
+ u.timediff = need[:timediff]
108
+ u.status = need[:status]
109
+
110
+ (need/:subject).each do |subject|
111
+ u.subject = subject.inner_html.gsub!(/\<\!\[CDATA\[(.*)\]\]\>/m, '\1')
112
+ end
113
+
114
+ u.text = need.search('text').first.inner_html.gsub!(/\<\!\[CDATA\[(.*)\]\]\>/m, '\1')
115
+
116
+ result << u
117
+ end
118
+ end
119
+ return result[0]
120
+ end
121
+
122
+
123
+
124
+ ##
125
+ end
126
+ end
127
+ end
@@ -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.gsub!(/\<\!\[CDATA\[(.*)\]\]\>/m, '\1')
22
+
23
+
24
+
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ module Needish
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 9
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/needish'
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNeedish < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: michelson-needish
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ platform: ruby
6
+ authors:
7
+ - Miguel Michelson Martinez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-08 00:00:00 -08:00
13
+ default_executable: needish
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.0
23
+ version:
24
+ description: This gem provides methods to access the needish.com api
25
+ email:
26
+ - miguelmichelson@gmail.com
27
+ executables:
28
+ - needish
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - License.txt
34
+ - Manifest.txt
35
+ - PostInstall.txt
36
+ - README.txt
37
+ files:
38
+ - History.txt
39
+ - License.txt
40
+ - Manifest.txt
41
+ - PostInstall.txt
42
+ - README.txt
43
+ - Rakefile
44
+ - bin/needish
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
+ - lib/needish/command.rb
54
+ - test/test_helper.rb
55
+ - test/test_needish.rb
56
+ has_rdoc: true
57
+ homepage: http://needish-gem.rubyforge.org
58
+ post_install_message: |+
59
+ Instalation Success!!
60
+
61
+ For more information on needish gem, see http://animalita.cl/needish-gem
62
+
63
+ cheers!
64
+
65
+
66
+
67
+
68
+ rdoc_options:
69
+ - --main
70
+ - README.txt
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project: needish-gem
88
+ rubygems_version: 1.2.0
89
+ signing_key:
90
+ specification_version: 2
91
+ summary: This gem provides methods to access the needish.com api
92
+ test_files:
93
+ - test/test_helper.rb
94
+ - test/test_needish.rb