convore 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,11 +1,16 @@
1
1
  Convore API
2
2
  ===========
3
3
 
4
- Quick implementation of the Convore.com API in ruby.
4
+ Convore!
5
+ -----
6
+ Convore's ruby gem!
7
+
5
8
 
6
9
  Usage
7
10
  -----
8
11
 
12
+ Client:
13
+
9
14
  require 'convore'
10
15
 
11
16
  @client = Convore::Client.new
@@ -6,10 +6,10 @@ Gem::Specification.new do |s|
6
6
  s.name = "convore"
7
7
  s.version = Convore::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Marian Rudzynski"]
10
- s.email = ["mr@impaled.org"]
9
+ s.authors = ["Marian Rudzynski", "RyanonRails"]
10
+ s.email = ["mr@impaled.org", "Ryan.Michael.Jones@gmail.com"]
11
11
  s.homepage = ""
12
- s.summary = %q{A hasty convore.com API implementation in ruby}
12
+ s.summary = %q{A convore.com API implementation in ruby}
13
13
  s.description = %q{}
14
14
 
15
15
  # s.rubyforge_project = "convore"
@@ -4,14 +4,13 @@ require 'json'
4
4
  module Convore
5
5
  end
6
6
 
7
- require 'convore/version'
8
-
9
- require 'convore/api'
10
- require 'convore/base'
11
- require 'convore/user'
12
- require 'convore/group'
13
- require 'convore/topic'
14
- require 'convore/message'
15
- require 'convore/star'
16
- require 'convore/client'
7
+ require_relative 'convore/version'
17
8
 
9
+ require_relative 'convore/api'
10
+ require_relative 'convore/base'
11
+ require_relative 'convore/user'
12
+ require_relative 'convore/group'
13
+ require_relative 'convore/topic'
14
+ require_relative 'convore/message'
15
+ require_relative 'convore/client'
16
+ require_relative 'convore/account'
@@ -0,0 +1,33 @@
1
+ require 'rest-client'
2
+
3
+ module Convore
4
+ class Account < Base
5
+ attr_accessor :username, :password
6
+
7
+ def initialize(username, password)
8
+ @username = username
9
+ @password = password
10
+ end
11
+
12
+ #Use this method to check if the user is properly logged in (also get user id)
13
+ def verified?
14
+ RestClient.get "https://#{@username}:#{@password}@convore.com/api/account/verify.json"
15
+ end
16
+
17
+ #Mark all messages as read
18
+ def mark_all_read
19
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/account/mark_read.json", {}
20
+ end
21
+
22
+ #Get members online now
23
+ def get_members_online
24
+ RestClient.get "https://#{@username}:#{@password}@convore.com/api/account/online.json"
25
+ end
26
+
27
+ #Get the users mentions
28
+ def get_mentions
29
+ RestClient.get "https://#{@username}:#{@password}@convore.com/api/account/online.json"
30
+ end
31
+
32
+ end
33
+ end
@@ -1,11 +1,12 @@
1
1
  module Convore
2
2
  class Base
3
- attr_accessor :attributes
3
+ attr_accessor :attributes, :username, :password
4
4
 
5
5
  def initialize
6
6
  @attributes ||= {}
7
7
  end
8
8
 
9
+
9
10
  def method_missing(method, *args)
10
11
  if method.match(/\=/)
11
12
  @attributes[method.to_s.gsub(/\=$/, '').to_sym] = args.first
@@ -15,6 +16,7 @@ module Convore
15
16
  end
16
17
  raise NoMethodError.new("no such method: #{method}")
17
18
  end
19
+
18
20
 
19
21
  class << self
20
22
 
@@ -1,5 +1,100 @@
1
+ #If posts don't have a mandatory payload they need to be fed a hash {}
2
+ require 'rest-client'
3
+
1
4
  module Convore
2
5
  class Group < Base
6
+ attr_accessor :username, :password
7
+
8
+ def initialize(username, password)
9
+ @username = username
10
+ @password = password
11
+ end
12
+
13
+ #Get a list of the current user's groups
14
+ def get_groups
15
+ RestClient.get "https://#{@username}:#{@password}@convore.com/api/groups.json"
16
+ end
17
+
18
+ #Create a new group.
19
+ def create_group(hash)
20
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/groups/create.json",
21
+ {:name => hash[:name],
22
+ :kind => hash[:kind],
23
+ #from here down optional
24
+ :description => hash[:description],
25
+ :slug => hash[:slug]}
26
+ end
27
+
28
+ #Get detailed information about the group
29
+ def get_group_info(group_id)
30
+ if group_id.integer?
31
+ RestClient.get "https://#{@username}:#{@password}@convore.com/api/groups/#{group_id}.json"
32
+ end
33
+ end
34
+
35
+ #Get the group members
36
+ def get_group_members(group_id, *hash)
37
+ if group_id.integer?
38
+ RestClient.get "https://#{@username}:#{@password}@convore.com/api/groups/#{group_id}/members.json",
39
+ #from here down optional
40
+ #{:filter => hash[:admin]}
41
+ hash[0]
42
+ end
43
+ end
44
+
45
+ #Join a public group
46
+ def join_public_group(group_id)
47
+ if group_id.integer?
48
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/groups/#{group_id}/join.json", {}
49
+ end
50
+ end
51
+
52
+ #Requests to join a private group
53
+ def join_private_group(group_id)
54
+ if group_id.integer?
55
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/groups/#{group_id}/request.json", ()
56
+ end
57
+ end
58
+
59
+ #Leave a group
60
+ def leave_group(group_id)
61
+ if group_id.integer?
62
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/groups/#{group_id}/leave.json", {}
63
+ end
64
+ end
65
+
66
+ #Get group members online now
67
+ def get_online_members(group_id)
68
+ if group_id.integer?
69
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/groups/#{group_id}/online.json", {}
70
+ end
71
+ end
72
+
73
+ #Get the latest topics in a group
74
+ def get_latest_topics(group_id, *hash)
75
+ if group_id.integer?
76
+ RestClient.get "https://#{@username}:#{@password}@convore.com/api/groups/#{group_id}/topics.json",
77
+ #from here down optional (pagination)
78
+ #{:until_id => hash[:until_id]}
79
+ hash[0]
80
+ end
81
+ end
82
+
83
+ #Create a new topic
84
+ def create_topic(group_id, hash)
85
+ if group_id.integer?
86
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/groups/#{group_id}/topics/create.json",
87
+ {:name => hash[:name]}
88
+ end
89
+ end
90
+
91
+ #Mark all messages in the group as read
92
+ def mark_all_read(group_id)
93
+ if group_id.integer?
94
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/groups/#{group_id}/mark_read.json", {}
95
+ end
96
+ end
97
+
3
98
  def self.api
4
99
  'group'
5
100
  end
@@ -1,7 +1,25 @@
1
1
  module Convore
2
2
  class Message < Base
3
- def text
4
- message
3
+
4
+ def initialize(username, password)
5
+ @username = username
6
+ @password = password
5
7
  end
8
+
9
+ #Star a message. If the message has already been starred by this user,
10
+ # this endpoint will then unstar the message.
11
+ def star_message(message_id)
12
+ if message_id.integer?
13
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/messages/#{message_id}/star.json", {}
14
+ end
15
+ end
16
+
17
+ #Delete a message. You must be the creator of the message or a group admin in order to delete the message.
18
+ def delete_message(message_id)
19
+ if message_id.integer?
20
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/messages/#{message_id}/delete.json", {}
21
+ end
22
+ end
23
+
6
24
  end
7
25
  end
@@ -1,5 +1,62 @@
1
1
  module Convore
2
2
  class Topic < Base
3
+
4
+ def initialize(username, password)
5
+ @username = username
6
+ @password = password
7
+ end
8
+
9
+ #Get detailed information about the topic
10
+ def get_topic(topic_id)
11
+ if topic_id.integer?
12
+ RestClient.get "https://#{@username}:#{@password}@convore.com/api/topics/#{topic_id}.json"
13
+ end
14
+ end
15
+
16
+ #Get the latest messages in a topic. Use the optional until_id parameter
17
+ #to paginate and get prior messages. Set the optional mark_read parameter
18
+ #to false to leave the messages as unread
19
+ def get_topic_messages(topic_id, *hash)
20
+ if topic_id.integer?
21
+ RestClient.get "https://#{@username}:#{@password}@convore.com/api/topics/#{topic_id}/messages.json",
22
+ #Optional Parms
23
+ #until_id
24
+ #mark_read
25
+ hash[0]
26
+ end
27
+ end
28
+
29
+ #Post a new message
30
+ def create_message(topic_id, hash)
31
+ if topic_id.integer?
32
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/topics/#{topic_id}/messages/create.json",
33
+ {:message => hash[:message]}
34
+ end
35
+ end
36
+
37
+ #Delete a topic. You must be the creator of the topic or a
38
+ # group admin in order to delete the topic.
39
+ def delete_topic(topic_id)
40
+ if topic_id.integer?
41
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/topics/#{topic_id}/delete.json", {}
42
+ end
43
+ end
44
+
45
+ #Edit a topic. You must be the creator of the topic or a group admin in order to edit the topic.
46
+ def edit_topic(topic_id, hash)
47
+ if topic_id.integer?
48
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/topics/#{topic_id}/edit.json",
49
+ {:name => hash[:name]}
50
+ end
51
+ end
52
+
53
+ #Mark all messages in a topic as read
54
+ def mark_read(topic_id)
55
+ if topic_id.integer?
56
+ RestClient.post "https://#{@username}:#{@password}@convore.com/api/topics/#{topic_id}/mark_read.json", {}
57
+ end
58
+ end
59
+
3
60
  def self.api
4
61
  'topic'
5
62
  end
@@ -1,4 +1,16 @@
1
1
  module Convore
2
2
  class User < Base
3
+
4
+ def initialize(username, password)
5
+ @username = username
6
+ @password = password
7
+ end
8
+
9
+ #Get detailed information about the user
10
+ def get_info(user_id)
11
+ if user_id.integer?
12
+ RestClient.get "https://#{@username}:#{@password}@convore.com/api/users/#{user_id}.json"
13
+ end
14
+ end
3
15
  end
4
16
  end
@@ -1,3 +1,3 @@
1
1
  module Convore
2
- VERSION = "0.0.0"
2
+ VERSION = "0.0.1"
3
3
  end
@@ -0,0 +1,39 @@
1
+ #TODO: More robust checkingthen 200, works for now though
2
+
3
+ require 'test/unit'
4
+ require '../lib/convore'
5
+
6
+ class Test_Account < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @username = 'Botticus'
10
+ @password = 'bot123'
11
+ end
12
+
13
+ def test_verified?
14
+ account = Convore::Account.new(@username, @password)
15
+ response = account.verified?
16
+ assert_equal(response.code, 200)
17
+ end
18
+
19
+ def test_mark_all_read
20
+ account = Convore::Account.new(@username, @password)
21
+ response = account.mark_all_read
22
+ assert_equal(response.code, 200)
23
+ end
24
+
25
+ def test_get_members_online
26
+ account = Convore::Account.new(@username, @password)
27
+ response = account.get_members_online
28
+ assert_equal(response.code, 200)
29
+ end
30
+
31
+ def test_get_mentions
32
+ account = Convore::Account.new(@username, @password)
33
+ response = account.get_mentions
34
+ assert_equal(response.code, 200)
35
+ end
36
+
37
+ end
38
+
39
+
@@ -0,0 +1,98 @@
1
+ require 'test/unit'
2
+ require '../lib/convore'
3
+
4
+ class Test_Group < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @username = 'Botticus'
8
+ @password = 'bot123'
9
+ end
10
+
11
+
12
+ def test_get_groups
13
+ group = Convore::Group.new(@username, @password)
14
+ response = group.get_groups
15
+ assert_equal(response.code, 200)
16
+ end
17
+
18
+ def test_create_group
19
+ group = Convore::Group.new(@username, @password)
20
+ hash = {:name => 'testgroup', :kind => 'private',
21
+ :description => 'this is a test group', :slug => 'test' }
22
+ response = group.create_group(hash)
23
+ assert_equal(response.code, 200)
24
+ end
25
+
26
+ def test_get_group_info
27
+ group = Convore::Group.new(@username, @password)
28
+ response = group.get_group_info(7939)
29
+ assert_equal(response.code, 200)
30
+ end
31
+
32
+ #1 parms
33
+ def test_get_group_members_1
34
+ group = Convore::Group.new(@username, @password)
35
+ response = group.get_group_members(7939)
36
+ assert_equal(response.code, 200)
37
+ end
38
+
39
+ #2 parms
40
+ def test_get_group_members_2
41
+ group = Convore::Group.new(@username, @password)
42
+ response = group.get_group_members(7939, {:filter => 'admin'})
43
+ assert_equal(response.code, 200)
44
+ end
45
+
46
+ def test_join_public_group
47
+ group = Convore::Group.new(@username, @password)
48
+ response = group.join_public_group(7939)
49
+ assert_equal(response.code, 200)
50
+ end
51
+
52
+ def test_join_private_group
53
+ group = Convore::Group.new(@username, @password)
54
+ response = group.join_public_group(8595)
55
+ assert_equal(response.code, 200)
56
+ end
57
+
58
+ def test_leave_group
59
+ group = Convore::Group.new(@username, @password)
60
+ response = group.leave_group(7939)
61
+ assert_equal(response.code, 200)
62
+ end
63
+
64
+ def test_get_online_members
65
+ group = Convore::Group.new(@username, @password)
66
+ response = group.leave_group(7939)
67
+ assert_equal(response.code, 200)
68
+ end
69
+
70
+ #1 parm
71
+ def test_get_latest_topics_1
72
+ group = Convore::Group.new(@username, @password)
73
+ response = group.get_latest_topics(7939)
74
+ assert_equal(response.code, 200)
75
+ end
76
+
77
+ #2 parm
78
+ def test_get_latest_topics_2
79
+ group = Convore::Group.new(@username, @password)
80
+ response = group.get_latest_topics(7939, {:until_id => 1})
81
+ assert_equal(response.code, 200)
82
+ end
83
+
84
+ def test_create_topic
85
+ group = Convore::Group.new(@username, @password)
86
+ response = group.create_topic(8482, {:name => "I am a test topic"})
87
+ assert_equal(response.code, 200)
88
+ end
89
+
90
+ def test_mark_all_read
91
+ group = Convore::Group.new(@username, @password)
92
+ response = group.mark_all_read(8482)
93
+ assert_equal(response.code, 200)
94
+ end
95
+
96
+ end
97
+
98
+
@@ -0,0 +1,24 @@
1
+ require 'test/unit'
2
+ require '../lib/convore'
3
+
4
+ class Test_Message < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @username = 'Botticus'
8
+ @password = 'bot123'
9
+ end
10
+
11
+
12
+ def test_star_message
13
+ message = Convore::Message.new(@username, @password)
14
+ response = message.star_message(8595)
15
+ assert_equal(response.code, 200)
16
+ end
17
+
18
+ def test_delete_message
19
+ message = Convore::Message.new(@username, @password)
20
+ response = message.delete_message(8595)
21
+ assert_equal(response.code, 200)
22
+ end
23
+
24
+ end
@@ -0,0 +1,48 @@
1
+ require 'test/unit'
2
+ require '../lib/convore'
3
+
4
+ class Test_Topic < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @username = 'Botticus'
8
+ @password = 'bot123'
9
+ end
10
+
11
+
12
+ def test_get_topic
13
+ topic = Convore::Topic.new(@username, @password)
14
+ response = topic.get_topic(8595)
15
+ assert_equal(response.code, 200)
16
+ end
17
+
18
+ def test_get_topic_messages
19
+ topic = Convore::Topic.new(@username, @password)
20
+ response = topic.get_topic_messages(8595, { :until_id => 11, :mark_read => 'false'})
21
+ assert_equal(response.code, 200)
22
+ end
23
+
24
+ def test_create_message
25
+ topic = Convore::Topic.new(@username, @password)
26
+ response = topic.get_topic_messages(8595, {:message => 'waffles123123'})
27
+ assert_equal(response.code, 200)
28
+ end
29
+
30
+ def test_delete_topic
31
+ topic = Convore::Topic.new(@username, @password)
32
+ response = topic.delete_topic(8595)
33
+ assert_equal(response.code, 200)
34
+ end
35
+
36
+ def test_edit_topic
37
+ topic = Convore::Topic.new(@username, @password)
38
+ response = topic.edit_topic(8595, {:topic_text => "Y so srs?"} )
39
+ assert_equal(response.code, 200)
40
+ end
41
+
42
+ def test_mark_read
43
+ topic = Convore::Topic.new(@username, @password)
44
+ response = topic.mark_read(8595 )
45
+ assert_equal(response.code, 200)
46
+ end
47
+
48
+ end
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+ require '../lib/convore'
3
+
4
+ class Test_User < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @username = 'Botticus'
8
+ @password = 'bot123'
9
+ end
10
+
11
+
12
+ def test_get_info
13
+ message = Convore::User.new(@username, @password)
14
+ response = message.get_info(8595)
15
+ assert_equal(response.code, 200)
16
+ end
17
+
18
+ end
metadata CHANGED
@@ -5,22 +5,24 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 0
9
- version: 0.0.0
8
+ - 1
9
+ version: 0.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Marian Rudzynski
13
+ - RyanonRails
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-02-15 00:00:00 +01:00
18
+ date: 2011-04-18 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
21
22
  description: ""
22
23
  email:
23
24
  - mr@impaled.org
25
+ - Ryan.Michael.Jones@gmail.com
24
26
  executables: []
25
27
 
26
28
  extensions: []
@@ -34,16 +36,20 @@ files:
34
36
  - Rakefile
35
37
  - convore.gemspec
36
38
  - lib/convore.rb
39
+ - lib/convore/account.rb
37
40
  - lib/convore/api.rb
38
41
  - lib/convore/base.rb
39
42
  - lib/convore/client.rb
40
43
  - lib/convore/group.rb
41
- - lib/convore/mention.rb
42
44
  - lib/convore/message.rb
43
- - lib/convore/star.rb
44
45
  - lib/convore/topic.rb
45
46
  - lib/convore/user.rb
46
47
  - lib/convore/version.rb
48
+ - test/test_account.rb
49
+ - test/test_group.rb
50
+ - test/test_message.rb
51
+ - test/test_topic.rb
52
+ - test/test_user.rb
47
53
  has_rdoc: true
48
54
  homepage: ""
49
55
  licenses: []
@@ -75,6 +81,10 @@ rubyforge_project:
75
81
  rubygems_version: 1.3.7
76
82
  signing_key:
77
83
  specification_version: 3
78
- summary: A hasty convore.com API implementation in ruby
79
- test_files: []
80
-
84
+ summary: A convore.com API implementation in ruby
85
+ test_files:
86
+ - test/test_account.rb
87
+ - test/test_group.rb
88
+ - test/test_message.rb
89
+ - test/test_topic.rb
90
+ - test/test_user.rb
@@ -1,4 +0,0 @@
1
- module Convore
2
- class Mention < Base
3
- end
4
- end
@@ -1,17 +0,0 @@
1
- module Convore
2
- class Star < Base
3
- class << self
4
- def from_json(json)
5
- object = new
6
- object.user = User.from_json(json['user'])
7
- object.message = Message.from_json(json['star']['message'])
8
- object.star = json['kind'] == 'star' ? true : false
9
- object
10
- end
11
- end
12
-
13
- def star?
14
- star
15
- end
16
- end
17
- end