Class: Needish::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/needish/base.rb

Constant Summary collapse

@@api_url =

Needish’s url, duh!

'api.needish.com'
@@timelines =

Timelines exposed by the needish api

[:friends, :public, :user]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, password, apikey) ⇒ Base

Initializes the configuration for making requests to needish



22
23
24
# File 'lib/needish/base.rb', line 22

def initialize(email, password, apikey)
  @config, @config[:email], @config[:password],@config[:apikey] = {}, email, password,"?app_key=#{apikey}"
end

Class Method Details

.timelinesObject



17
18
19
# File 'lib/needish/base.rb', line 17

def self.timelines
  @@timelines
end

Instance Method Details

#add_help(id, text) ⇒ Object

Post a new Need for the authenticating user.



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/needish/base.rb', line 99

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

#add_need(subject, text) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/needish/base.rb', line 85

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

#all_needsObject

Returns up to 100 recent public needs, ordered by descending date of creation.



54
55
56
# File 'lib/needish/base.rb', line 54

def all_needs
  needs_generic_data(request("needs/all.xml", :auth => true))
end

#friends(id) ⇒ Object

Returns an array of users who are in your friends list



44
45
46
# File 'lib/needish/base.rb', line 44

def friends(id)
 friends_data(request("users/friends/#{id}.xml", :auth => true))
end

#friends_needsObject

Returns up to 100 recent needs of the authenticating user friends, ordered by descending date of creation.



59
60
61
# File 'lib/needish/base.rb', line 59

def friends_needs
  needs_generic_data(request("needs/friends.xml", :auth => true))
end

#helps(id) ⇒ Object

Returns up to 100 helps for the given need, ordered by date of creation.



74
75
76
# File 'lib/needish/base.rb', line 74

def helps(id)
  helps_data(request("needs/helps/#{id}.xml", :auth => true))
end

#hot_needsObject

Returns the most active needs, ordered by descending number of recent helps.



49
50
51
# File 'lib/needish/base.rb', line 49

def hot_needs
  needs_generic_data(request("needs/hot.xml", :auth => true))
end

#meObject

returns user data information



29
30
31
# File 'lib/needish/base.rb', line 29

def me
    users(request("users/authenticate.xml", :auth => true))
end

#needs_from_user(id) ⇒ Object

Returns up to 100 recent public needs created by the given user, ordered by descending date of creation.



64
65
66
# File 'lib/needish/base.rb', line 64

def needs_from_user(id)
  needs_generic_data(request("needs/user/#{id}.xml", :auth => true))
end

#user_needs(id) ⇒ Object

Returns the profile of a given user, including the recent needs. The needs are ordered by descending date of creation.



39
40
41
# File 'lib/needish/base.rb', line 39

def user_needs(id)
  needs_data(request("users/profile/#{id}.xml", :auth => true))
end

#user_profile(id) ⇒ Object

Returns the profile of a given user,



34
35
36
# File 'lib/needish/base.rb', line 34

def (id)
  users(request("users/profile/#{id}.xml", :auth => true))
end

#view_need(id) ⇒ Object

Returns the given need



69
70
71
# File 'lib/needish/base.rb', line 69

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