Module: TheCity::API::Needs

Includes:
Utils
Included in:
Client
Defined in:
lib/the_city/api/needs.rb

Instance Method Summary collapse

Instance Method Details

#need(id) ⇒ TheCity::Need #need(id, options = {}) ⇒ TheCity::Need

Returns a need by id

Overloads:

  • #need(id) ⇒ TheCity::Need

    Parameters:

    • id (Integer)

      The id of the need.

  • #need(id, options = {}) ⇒ TheCity::Need

    Parameters:

    • id (Integer)

      The id of the need.

    • options (Hash) (defaults to: {})

      A customizable set of options.

    Options Hash (options):

    • :force_download (Boolean)

      Forces the request to hit the server and flush the cached response

Returns:

Raises:

See Also:



41
42
43
44
45
46
47
# File 'lib/the_city/api/needs.rb', line 41

def need(*args)
  @needs ||= {}
  arguments = TheCity::Arguments.new(args)
  nid = args.shift
  @needs[nid] = nil if arguments.options.delete(:force_download)
  @needs[nid] ||= object_from_response(TheCity::Need, :get, "/needs/#{nid}", arguments.options, {:client => self})
end

#post_need(options) ⇒ TheCity::Need

Posts a need to The City

Parameters:

  • options (Hash)

    A customizable set of options.

Options Hash (options):

  • :group_id (Integer)

    The id of the group you will be posting to.

  • :title (String)

    The title of the need.

  • :body (String)

    The body text of the need.

Returns:

Raises:

See Also:



20
21
22
23
24
25
26
# File 'lib/the_city/api/needs.rb', line 20

def post_need(options)
  raise(Error::ArgumentError, "Must supply a options[:group_id] for the needs's originating group") unless options[:group_id]
  raise(Error::ArgumentError, "Title (options[:title]) required") unless options[:title]
  raise(Error::ArgumentError, "Body (options[:body]) required") unless options[:body]
  gid = options[:group_id] || 0
  object_from_response(TheCity::Need, :post, "/groups/#{gid}/needs/", options, {:client => self})
end