Class: Coop::Status

Inherits:
APIObject show all
Defined in:
lib/coop/api_object/status.rb

Instance Method Summary collapse

Methods inherited from APIObject

parse_response

Instance Method Details

#post!(message) ⇒ Object

Public: Post a status update to a group

message - The text for the status update

Examples

Status.new({ group_id: 12345 }).post! "Is this computer?"
# => "/statuses/123456"

Returns String of new status’ URL



25
26
27
28
29
30
31
# File 'lib/coop/api_object/status.rb', line 25

def post!(message)
  Coop.post(
    "/groups/#{self.group_id}/statuses", 
    query: { status: message }, 
    headers: { "Accept" => "application/xml" }
  ).headers["Location"]
end

#post_as_cobot!(message, api_key) ⇒ Object

Public: Post a status update to a group as Cobot

message - The text for the status update api_key - The API key needed to post as Cobot

Examples

Status.new({ group_id: 12345 }).post_as_cobot! "YES, THIS IS COMPUTER", "THISISMYSECRETKEY"
# => "/statuses/123456"

Returns String of new status’ URL



44
45
46
47
48
49
50
51
# File 'lib/coop/api_object/status.rb', line 44

def post_as_cobot!(message, api_key)
  Coop.post(
    "/groups/#{self.group_id}/statuses",
    query: { status: message, key: api_key }, 
    headers: { "Accept" => "application/xml" },
    basic_auth: nil
  ).headers["Location"]
end

#recentObject

Public: Get a group’s 50 most recent tweets

Examples

Status.new({ group_id: 12345 }).recent
# => [{"type" => "Note", "users" => ...}]

Returns an Array of statuses as APIObjects



11
12
13
# File 'lib/coop/api_object/status.rb', line 11

def recent
  Coop.get_parsed("/groups/#{self.group_id}/statuses")
end

#where(options = {}) ⇒ Object

Public: A poor man’s Arel for querying the status API

options - A hash of options, which can include either or both of:

user_id  => the id of the user
date     => a Date object

Examples

Status.new({ group_id: 12345 }).where({ user_id: 12345, date: Date.today })

Returns Array of APIObjects



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/coop/api_object/status.rb', line 64

def where(options = {})
  if options[:user_id] && options[:date]
    where_user_and_date(options[:user_id], options[:date])
  elsif options[:user_id]
    where_user(options[:user_id])
  elsif options[:date]
    where_date(options[:date])
  else
    recent
  end
end