bscofield-stammer 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +1 -1
- data/lib/stammer.rb +1 -9
- data/lib/stammer/client.rb +49 -13
- data/stammer.gemspec +1 -1
- metadata +1 -1
data/README.txt
CHANGED
data/lib/stammer.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# $Id$
|
2
2
|
|
3
|
-
# Equivalent to a header guard in C/C++
|
4
|
-
# Used to prevent the class/module from being loaded more than once
|
5
|
-
unless defined? Stammer
|
6
|
-
|
7
3
|
module Stammer
|
8
4
|
|
9
5
|
# :stopdoc:
|
@@ -49,8 +45,4 @@ module Stammer
|
|
49
45
|
|
50
46
|
end # module Stammer
|
51
47
|
|
52
|
-
Stammer.require_all_libs_relative_to __FILE__
|
53
|
-
|
54
|
-
end # unless defined?
|
55
|
-
|
56
|
-
# EOF
|
48
|
+
Stammer.require_all_libs_relative_to __FILE__
|
data/lib/stammer/client.rb
CHANGED
@@ -4,11 +4,16 @@ require 'net/https'
|
|
4
4
|
|
5
5
|
module Stammer
|
6
6
|
class Client
|
7
|
-
|
7
|
+
|
8
|
+
ACCEPTABLE_SUBSETS = [:all, :sent, :received, :following]
|
9
|
+
FORMAT = 'json'
|
10
|
+
HEADERS = {'User-Agent' => 'Stammer v0.0.3', 'Accept' => "text/#{FORMAT}"}
|
11
|
+
API_URL = "https://yammer.com/api/v1"
|
12
|
+
|
13
|
+
def initialize(user, password, secret = nil, client = nil)
|
8
14
|
@user = user
|
9
15
|
@password = password
|
10
|
-
|
11
|
-
|
16
|
+
|
12
17
|
unless !secret || !client
|
13
18
|
@secret = secret
|
14
19
|
@client = client
|
@@ -17,23 +22,54 @@ module Stammer
|
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|
20
|
-
|
21
|
-
|
25
|
+
# TODO: pagination via older_than/newer_than
|
26
|
+
def messages(subset = :all)
|
27
|
+
raise ArgumentError.new("Subset must be in [#{ACCEPTABLE_SUBSETS.join(', ')}]") unless ACCEPTABLE_SUBSETS.include?(subset)
|
28
|
+
subset = nil if subset == :all
|
29
|
+
MessageList.new(send_request('messages', subset.to_s))
|
30
|
+
end
|
31
|
+
|
32
|
+
# TODO: pagination via page
|
33
|
+
def users(id = nil)
|
34
|
+
UserList.new(send_request('users', id))
|
35
|
+
end
|
36
|
+
|
37
|
+
def tags(id = nil)
|
38
|
+
TagList.new(send_request('tags', id))
|
39
|
+
end
|
40
|
+
|
41
|
+
def update_status(status)
|
42
|
+
raise ArgumentError.new("must update with a status") if status.to_s == ""
|
43
|
+
url = URI.parse(API_URL + "/messages")
|
44
|
+
conn = create_connection(url)
|
45
|
+
res = conn.start do |http|
|
46
|
+
req = Net::HTTP::Post.new(url.path, HEADERS)
|
47
|
+
req.basic_auth(@user, @password)
|
48
|
+
req.form_data = {'body' => status}
|
49
|
+
http.request(req)
|
50
|
+
end
|
51
|
+
return res.is_a?(Net::HTTPCreated)
|
22
52
|
end
|
23
53
|
|
24
54
|
private
|
55
|
+
|
25
56
|
def send_request(*args)
|
26
|
-
url = URI.parse("
|
27
|
-
|
28
|
-
conn =
|
29
|
-
conn.
|
30
|
-
|
31
|
-
res = conn.start { |http|
|
32
|
-
req = Net::HTTP::Get.new(url.path, {'User-Agent' => 'Stammer v0.0.1', 'Accept' => 'text/json'})
|
57
|
+
url = URI.parse("#{API_URL}/#{args.compact.join('/')}.#{FORMAT}")
|
58
|
+
puts "grabbing #{url.to_s}"
|
59
|
+
conn = create_connection(url)
|
60
|
+
res = conn.start do |http|
|
61
|
+
req = Net::HTTP::Get.new(url.path, HEADERS)
|
33
62
|
req.basic_auth(@user, @password)
|
34
63
|
http.request(req)
|
35
|
-
|
64
|
+
end
|
36
65
|
JSON.load(res.body)
|
37
66
|
end
|
67
|
+
|
68
|
+
def create_connection(url)
|
69
|
+
conn = Net::HTTP.new(url.host, url.port)
|
70
|
+
conn.use_ssl = true
|
71
|
+
conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
72
|
+
conn
|
73
|
+
end
|
38
74
|
end
|
39
75
|
end
|
data/stammer.gemspec
CHANGED