Permalink
Browse files

Added Event model

  • Loading branch information...
1 parent 0add3d9 commit 802873b008a97d0ebb0583adbb4055fd4d01e5ad @numbata numbata committed May 16, 2012
Showing with 91 additions and 6 deletions.
  1. +5 −4 lib/timepad.rb
  2. +12 −0 lib/timepad/category.rb
  3. +19 −1 lib/timepad/event.rb
  4. +18 −0 test/timepad/category_test.rb
  5. +34 −0 test/timepad/event_test.rb
  6. +3 −1 test/timepad/maillist_test.rb
View
@@ -1,9 +1,10 @@
module Timepad
- autoload :Base, 'timepad/base'
- autoload :Version, 'timepad/version'
+ autoload :Base, 'timepad/base'
+ autoload :Version, 'timepad/version'
autoload :Maillist, 'timepad/maillist'
- autoload :Event, 'timepad/event'
- autoload :Config, 'timepad/config'
+ autoload :Event, 'timepad/event'
+ autoload :Category, 'timepad/category'
+ autoload :Config, 'timepad/config'
extend Config
end
View
@@ -0,0 +1,12 @@
+module Timepad
+ class Category < Base
+
+ # Get all categories
+ #
+ # @return [Array]
+ def self.get_list
+ request('getlist')
+ end
+
+ end
+end
View
@@ -1,3 +1,21 @@
module Timepad
- module Event < Base; end
+ class Event < Base
+
+ # Get all events
+ #
+ # @param [Hash{cat_id => String, limit => String, order_by =>String}]
+ # @return [Array]
+ def self.get_list params = {}
+ request('getlist', params)
+ end
+
+ # Get event by event_id
+ #
+ # @param [String] event_id
+ # @return [Array]
+ def self.get event_id
+ request('get', :e_id => event_id)
+ end
+
+ end
end
@@ -0,0 +1,18 @@
+require 'test_helper'
+
+class Timepad::CategoryTest < MiniTest::Unit::TestCase
+
+ def setup
+ Timepad.configure do |config|
+ config.key = 'api_key'
+ config.id = '7912'
+ end
+ end
+
+ def test_should_get_categories
+ stub_http_request(:get, "#{Timepad.endpoint}category_getlist")
+ .with(:query => {:code => Timepad.key, :id => Timepad.id})
+ .to_return(:body => '[]')
+ Timepad::Category.get_list
+ end
+end
View
@@ -0,0 +1,34 @@
+require 'test_helper'
+
+class Timepad::EventTest < MiniTest::Unit::TestCase
+
+ def setup
+ Timepad.configure do |config|
+ config.key = 'api_key'
+ config.id = '7912'
+ end
+ end
+
+ def test_should_get_events
+ stub_http_request(:get, "#{Timepad.endpoint}event_getlist")
+ .with(:query => {:code => Timepad.key, :id => Timepad.id})
+ .to_return(:body => '[]')
+ Timepad::Event.get_list
+ end
+
+ def test_should_get_events_by_category
+ category_id = 1
+ stub_http_request(:get, "#{Timepad.endpoint}event_getlist")
+ .with(:query => {:code => Timepad.key, :id => Timepad.id, :cat_id => category_id})
+ .to_return(:body => '[]')
+ Timepad::Event.get_list :cat_id => category_id
+ end
+
+ def test_shoul_get_event
+ event_id = 1
+ stub_http_request(:get, "#{Timepad.endpoint}event_get")
+ .with(:query => {:code => Timepad.key, :id => Timepad.id, :e_id => event_id})
+ .to_return(:body => '[]')
+ Timepad::Event.get event_id
+ end
+end
@@ -10,7 +10,9 @@ def setup
end
def test_should_get_mailists
- stub_http_request(:get, "#{Timepad.endpoint}maillist_getlist").with(:query => {:code=> Timepad.key, :id => Timepad.id}).to_return(:body=>'[]')
+ stub_http_request(:get, "#{Timepad.endpoint}maillist_getlist")
+ .with(:query => {:code => Timepad.key, :id => Timepad.id})
+ .to_return(:body => '[]')
Timepad::Maillist.get_list
end
end

0 comments on commit 802873b

Please sign in to comment.