Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some ideas for accessing messages and users
- Loading branch information
Jim Patterson
committed
Dec 20, 2008
1 parent
91f5fa6
commit f423171
Showing
11 changed files
with
215 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
require 'yammer' | ||
|
||
# Create a new Yammer Client | ||
yammer = Yammer::Client.new | ||
puts yammer.messages.inspect | ||
|
||
# Get all messages | ||
messages = yammer.messages | ||
puts messages.size | ||
puts messages.last.inspect | ||
|
||
# Print out all the users | ||
yammer.users.each do |u| | ||
puts "#{u.name} - #{u.me?}" | ||
end | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class String | ||
def to_boolean | ||
case self | ||
when 'true' | ||
true | ||
when 'false' | ||
false | ||
else | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--colour | ||
--format | ||
progress | ||
--loadby | ||
mtime | ||
--reverse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
$:.unshift File.join(File.dirname(__FILE__), "..", "lib") | ||
|
||
require 'spec' | ||
|
||
# Add helper methods here if relevant to multiple _spec.rb files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require File.join(File.dirname(__FILE__), '..', 'spec_helper') | ||
|
||
describe Yammer::Client, "#message" do | ||
before(:each) do | ||
@twitter = client_context | ||
@message = 'This is my unique message' | ||
@uris = Twitter::Client.class_eval("@@STATUS_URIS") | ||
@options = {:id => 666666} | ||
@request = mas_net_http_get(:basic_auth => nil) | ||
@response = mas_net_http_response(:success, '{}') | ||
@connection = mas_net_http(@response) | ||
@float = 43.3434 | ||
@status = Twitter::Status.new(:id => 2349343) | ||
@source = Twitter::Client.class_eval("@@defaults[:source]") | ||
end | ||
|
||
it "should return nil if nil is passed as value argument for :get case" do | ||
status = @twitter.status(:get, nil) | ||
status.should be_nil | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
# <message> | ||
# <id>1102</id> | ||
# <url>https://www.yammer.com/api/v1/messages/1102</url> | ||
# <web-url>https://www.yammer.com/messages/1102</web-url> | ||
# <replied-to-id>1101</replied-to-id> | ||
# <thread-id>1101</thread-id> | ||
# <body> | ||
# <plain>I love #yammer.</plain> | ||
# <parsed>I love [[tag:1000]].</parsed> | ||
# </body> | ||
# <message-type>update</message-type> | ||
# <client-type>web</client-type> | ||
# <sender-id>1002</sender-id> | ||
# <sender-type>user</sender-type> | ||
# <created-at>2008-09-12T17:35:43Z</created-at> | ||
# </message> | ||
|
||
class Yammer::Message | ||
|
||
attr_reader :id, :url, :web_url, :replied_to_id, :thread_id, | ||
:body_plain, :body_parsed, :message_type, :client_type, | ||
:sender_id, :sender_type | ||
|
||
def initialize(m) | ||
@id = m['id'] | ||
@url = m['url'] | ||
@web_url = m['web_url'] | ||
@replied_to_id = m['replied_to_id'] | ||
@thread_id = m['thread_id'] | ||
@body_plain = m['body']['plain'] | ||
@body_parsed = m['body']['parsed'] | ||
@message_type = m['message_type'] | ||
@client_type = m['client_type'] | ||
@sender_id = m['sender_id'] | ||
@sender_type = m['sender_type'] | ||
begin | ||
@created_at = m['created_at'] | ||
rescue ArgumentError => e | ||
@created_at = nil | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Yammer::MessageList < Array | ||
|
||
attr_reader :older_available, :ids | ||
|
||
def initialize(a, oa, c) | ||
super(a) | ||
@older_available = oa | ||
@client = c | ||
@ids = a.map {|m| m.id}.sort | ||
end | ||
|
||
def first | ||
self[0] | ||
end | ||
|
||
def last | ||
self[self.size - 1] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
class Yammer::User | ||
|
||
attr_reader :id, :url, :web_url, :name, :full_name, :mugshot_url, | ||
:job_title, :location, :stats, :contact, | ||
:hire_date, :birth_date, :network_name, :full_user | ||
|
||
def initialize(u, c) | ||
@client = c | ||
@id = u['id'] | ||
@url = u['url'] | ||
@web_url = u['web_url'] | ||
@name = u['name'] | ||
@full_name = u['full_name'] | ||
@mugshot_url = u['mugshot_url'] | ||
@job_title = u['job_title'] | ||
# These attributes will be nil when User is a reference | ||
@network_id = u['network_id'] | ||
@location = u['location'] | ||
@stats = u['stats'] | ||
@contact = u['contact'] | ||
@hire_date = u['hire_date'] | ||
@birth_date = u['birth_date'] | ||
@network_name = u['network_name'] | ||
end | ||
|
||
def network_id | ||
get_full_user unless @network_id | ||
@network_id | ||
end | ||
|
||
def location | ||
get_full_user unless @location | ||
@location | ||
end | ||
|
||
def stats | ||
get_full_user unless @stats | ||
@stats | ||
end | ||
|
||
def contact | ||
get_full_user unless @contact | ||
@contact | ||
end | ||
|
||
def hire_date | ||
get_full_user unless @hire_date | ||
@hire_date | ||
end | ||
|
||
def birth_date | ||
get_full_user unless @birth_date | ||
@birth_date | ||
end | ||
|
||
def network_name | ||
get_full_user unless @network_name | ||
@network_name | ||
end | ||
|
||
def me? | ||
@id == @client.me.id | ||
end | ||
|
||
private | ||
def get_full_user | ||
response = @client.access_token.get "/api/v1/users/#{id}.json" | ||
u = JSON.parse(response.body) | ||
initialize(u, @client) | ||
end | ||
|
||
end |