Skip to content

Commit

Permalink
change to 0.0.2 , The apikey passes to the method initialize, now is …
Browse files Browse the repository at this point in the history
…not a global variable, (security issues)
  • Loading branch information
michelson committed Jul 7, 2008
1 parent 4474830 commit 164fb7d
Show file tree
Hide file tree
Showing 18 changed files with 652 additions and 0 deletions.
Binary file added pkg/needish-0.0.2.gem
Binary file not shown.
Binary file added pkg/needish-0.0.2.tgz
Binary file not shown.
10 changes: 10 additions & 0 deletions pkg/needish-0.0.2/History.txt
@@ -0,0 +1,10 @@
== 0.0.2 2008-07-05

* 1 major enhancement:
* @@apikey desapears
*The apikey passes to the method initialize, now is not a global variable, (security issues)

== 0.0.1 2008-07-05

* 1 major enhancement:
* Initial release
20 changes: 20 additions & 0 deletions pkg/needish-0.0.2/License.txt
@@ -0,0 +1,20 @@
Copyright (c) 2008 Miguel Michelson Martinez

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 changes: 17 additions & 0 deletions pkg/needish-0.0.2/Manifest.txt
@@ -0,0 +1,17 @@
History.txt
License.txt
Manifest.txt
PostInstall.txt
README.txt
Rakefile
lib/needish.rb
lib/needish/version.rb
lib/needish/base.rb
lib/needish/easy_class_maker.rb
lib/needish/friend.rb
lib/needish/help.rb
lib/needish/need.rb
lib/needish/user.rb
test/test_helper.rb
test/test_needish.rb

9 changes: 9 additions & 0 deletions pkg/needish-0.0.2/PostInstall.txt
@@ -0,0 +1,9 @@
Instalation Success!!

For more information on needish gem, see http://animalita.cl/needish-gem

cheers!




102 changes: 102 additions & 0 deletions pkg/needish-0.0.2/README.txt
@@ -0,0 +1,102 @@
= needish

* FIX (url)

== DESCRIPTION:

This Gems provides basic methods to access the Nedish.com api

== FEATURES/PROBLEMS:

lists the user profile, user friends , needs and helps from a need
sends needs, helps

-problems.
no detected yet!

-todo
search methods
make friends etc..

== SYNOPSIS:

*examples

login to needish
pass to login user and pass AND apikey!! (since 0.0.2)

<pre>login = Needish::Base.new('miguelmichelson@gmail.com','********' ,'apikey2234455566')</pre>

obtain the user logged data

<pre>miguel = login.me</pre>

obtain the user id

<pre>miguel.id</pre>

obtain the user friends

<pre>login.user_friends(miguel.id)</pre>

obtain the needs

<pre>login.user_needs(me.id)</pre>

obtain the needs helps

<pre>login.helps(user_needs(me.id)[0].id)</pre>

Other methods

add need, pass subject and text

<pre>login.add_need('subject','text')</pre>

add help, pass need id and text

<pre>login.add_help(need.id,'text')</pre>



== REQUIREMENTS:

this gem requires hricot,

sudo gem install hpricot


== INSTALL:

to install this gem simply do :

git clone git://github.com/michelson/needish-gem.git

cd needish-gem

sudo install gem pkg/needish-0.0.1.gem

== LICENSE:

(The MIT License)

Copyright (c) 2008 FIXME full name

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 changes: 4 additions & 0 deletions pkg/needish-0.0.2/Rakefile
@@ -0,0 +1,4 @@
require 'config/requirements'
require 'config/hoe' # setup Hoe + all gem configuration

Dir['tasks/**/*.rake'].each { |rake| load rake }
14 changes: 14 additions & 0 deletions pkg/needish-0.0.2/lib/needish.rb
@@ -0,0 +1,14 @@
%w(uri cgi net/http yaml rubygems hpricot active_support).each { |f| require f }

$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))



require 'needish/version'
require 'needish/easy_class_maker'
require 'needish/base'
require 'needish/user'
require 'needish/friend'
require 'needish/need'
require 'needish/help'
194 changes: 194 additions & 0 deletions pkg/needish-0.0.2/lib/needish/base.rb
@@ -0,0 +1,194 @@
# very inspired in twitter gem
# This is the base class for the needish library. It makes all the requests
# to needish, parses the xml (using hpricot) and returns ruby objects to play with.
# The private methods in this one are pretty fun. Be sure to check out users, needs and helps...
module Needish
class Untwitterable < StandardError; end
class CantConnect < Untwitterable; end
class BadResponse < Untwitterable; end
class UnknownTimeline < ArgumentError; end

class Base
# Needish's url, duh!
@@api_url = 'api.needish.com'
# Timelines exposed by the needish api
@@timelines = [:friends, :public, :user]

def self.timelines
@@timelines
end

# Initializes the configuration for making requests to needish
def initialize(email, password, apikey)
@config, @config[:email], @config[:password],@config[:apikey] = {}, email, password,"?app_key=#{apikey}"
end



#returns user data information
def me
users(request("users/authenticate.xml", :auth => true))
end

# Returns the profile of a given user,
def user_profile(id)
users(request("users/profile/#{id}.xml", :auth => true))
end

# Returns the profile of a given user, including the recent needs. The needs are ordered by descending date of creation.
def user_needs(id)
needs_data(request("users/profile/#{id}.xml", :auth => true))
end

# Returns an array of users who are in your friends list
def friends(id)
friends_data(request("users/friends/#{id}.xml", :auth => true))
end

# Returns the most active needs, ordered by descending number of recent helps.
def hot_needs
needs_generic_data(request("needs/hot.xml", :auth => true))
end

# Returns up to 100 recent public needs, ordered by descending date of creation.
def all_needs
needs_generic_data(request("needs/all.xml", :auth => true))
end

#Returns up to 100 recent needs of the authenticating user friends, ordered by descending date of creation.
def friends_needs
needs_generic_data(request("needs/friends.xml", :auth => true))
end

#Returns up to 100 recent public needs created by the given user, ordered by descending date of creation.
def needs_from_user(id)
needs_generic_data(request("needs/user/#{id}.xml", :auth => true))
end

#Returns the given need
def view_need(id)
needs_view_data(request("needs/view/#{id}.xml", :auth => true))
end

# Returns up to 100 helps for the given need, ordered by date of creation.
def helps(id)
helps_data(request("needs/helps/#{id}.xml", :auth => true))
end


# Send data


# Post a new Need for the authenticating user.

# http://api.needish.com/needs/add.format
def add_need(subject, text)
url = URI.parse("http://#{@@api_url}/needs/add.xml#{@config[:apikey]}")
req = Net::HTTP::Post.new(url.path)

req.basic_auth(@config[:email], @config[:password])
req.set_form_data({'text' => text, 'subject' => subject})

response = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
parse(response.body)

end

# Post a new Need for the authenticating user.

def add_help(id, text)
url = URI.parse("http://#{@@api_url}/helps/add/#{id}.xml#{@config[:apikey]}")
req = Net::HTTP::Post.new(url.path+@config[:apikey])

req.basic_auth(@config[:email], @config[:password])
req.set_form_data({'text' => text})

response = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
parse(response.body)

end

#to do
# twitter style
# Befriends the user specified in the ID parameter as the authenticating user.

# def create_friendship(id_or_screenname)
# users(request("friends/add/#{id_or_screenname}.xml", :auth => true)).first
#end

#def destroy_friendship(id_or_screenname)
# users(request("friends/destroy/#{id_or_screenname}.xml", :auth => true)).first
#end

#def follow(id_or_screenname)
# users(request("notifications/follow/#{id_or_screenname}.xml", :auth => true)).first
#end

#def leave(id_or_screenname)
# users(request("notifications/leave/#{id_or_screenname}.xml", :auth => true)).first
#end


private
# Converts an hpricot doc to an array of statuses

# Converts an hpricot doc to an array of ..

def users(doc)
#(doc/:user).inject([]) { |users, user| users << User.new_from_xml(user); users }
User.new_from_xml(doc)
end

def friends_data(doc)
# (doc/:user).inject([]) { |users, user| users << Friend.new_from_xml(user); users }

Friend.new_from_xml(doc)
end

def needs_data(doc)
Need.new_from_xml(doc)
end

def needs_generic_data(doc)
Need.generic_from_xml(doc)
end
def needs_view_data(doc)
Need.generic_view_from_xml(doc)
end

def helps_data(doc)
Help.new_from_xml(doc)
end

# Calls whatever api method requested that deals with statuses
#
# ie: call(:public_timeline, :auth => false)
def call(method, options={})
options.reverse_merge!({ :auth => true, :args => {} })
path = "statuses/#{method.to_s}.xml"
path += '?' + options[:args].inject('') { |qs, h| qs += "#{h[0]}=#{h[1]}&"; qs } unless options[:args].blank?
request(path, options)
end

def request(path, options={})
options.reverse_merge!({:headers => { "User-Agent" => @config[:email] }})
begin
response = Net::HTTP.start(@@api_url, 80) do |http|
req = Net::HTTP::Get.new('/' + path+@config[:apikey], options[:headers])
req.basic_auth(@config[:email], @config[:password]) if options[:auth]
http.request(req)
end
#puts req.body

raise BadResponse unless response.message == 'OK'
parse(response.body)
rescue
raise CantConnect
end
end

def parse(response)
Hpricot.XML(response)
end
end
end

0 comments on commit 164fb7d

Please sign in to comment.