timepad 0.0.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +1 -0
- data/README.md +56 -3
- data/Rakefile +8 -0
- data/lib/timepad.rb +36 -1
- data/lib/timepad/base.rb +24 -5
- data/lib/timepad/category.rb +6 -2
- data/lib/timepad/client.rb +51 -0
- data/lib/timepad/config.rb +9 -0
- data/lib/timepad/event.rb +30 -7
- data/lib/timepad/mail.rb +44 -0
- data/lib/timepad/maillist.rb +34 -5
- data/lib/timepad/version.rb +1 -1
- data/test/test_helper.rb +1 -0
- data/test/timepad/base_test.rb +38 -0
- data/test/timepad/category_test.rb +7 -3
- data/test/timepad/client_test.rb +46 -0
- data/test/timepad/event_test.rb +72 -22
- data/test/timepad/mail_test.rb +20 -0
- data/test/timepad/maillist_test.rb +44 -4
- data/test/timepad_test.rb +37 -0
- data/timepad.gemspec +2 -1
- metadata +31 -5
- data/README.rdoc +0 -4
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,57 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Timepad
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/kaize/timepad.png)](http://travis-ci.org/kaize/timepad)
|
4
|
+
|
5
|
+
[https://github.com/timepad/timepad\_api/wiki]
|
6
|
+
|
7
|
+
## Установка
|
8
|
+
|
9
|
+
Добавить в Gemfile строки:
|
10
|
+
|
11
|
+
gem 'timepad'
|
12
|
+
|
13
|
+
Затем запустить:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Настройка
|
18
|
+
|
19
|
+
Для работы гема требуется в конфигурации указать `id` и `key`, которые можно найти на странице настроек вашей организации [http://mycompany.timepad.ru/profile]
|
20
|
+
|
21
|
+
#config/initializers/timepad.rb
|
22
|
+
Timepad.configure do |config|
|
23
|
+
config.id = 1
|
24
|
+
config.key = 'abcde'
|
25
|
+
end
|
26
|
+
|
27
|
+
## События
|
28
|
+
|
29
|
+
# Получение списка событий
|
30
|
+
events = Timepad.event.get_list :limit => 1, :order_by => :begin
|
31
|
+
|
32
|
+
# Альтернативный вариант
|
33
|
+
events = Timepad.events
|
34
|
+
|
35
|
+
# Получение события
|
36
|
+
event = Timepad.event.get 1
|
37
|
+
event = Timepad.event 1
|
38
|
+
## Списки рассылок
|
39
|
+
|
40
|
+
# Создание списка рассылок
|
41
|
+
Timepad.maillist.create 'maillist_title', [{email => 'test@example.com'}]
|
42
|
+
|
43
|
+
# Получение списка рассылок
|
44
|
+
maillists = Timepad.maillist.get_list
|
45
|
+
|
46
|
+
# Выгрузка списка рассылок
|
47
|
+
maillist = Timepad.maillist.get maillist_id
|
48
|
+
|
49
|
+
# Добавление подписчика в рассылку
|
50
|
+
Timepad.maillist.add_items maillist_id, [{email => 'test@exmaple.com'}]
|
51
|
+
|
52
|
+
## Письма рассылок
|
53
|
+
|
54
|
+
# Отправка письма в рассылку
|
55
|
+
Timepad.mail.create :subject => 'subject', :text => 'text', :maillists => [1,2], :subscribers => ['a@a.a', 'b@b.b']
|
56
|
+
|
3
57
|
|
4
|
-
api
|
data/Rakefile
CHANGED
data/lib/timepad.rb
CHANGED
@@ -1,10 +1,45 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'active_support/core_ext/enumerable'
|
4
|
+
|
1
5
|
module Timepad
|
2
6
|
autoload :Base, 'timepad/base'
|
3
7
|
autoload :Version, 'timepad/version'
|
4
8
|
autoload :Maillist, 'timepad/maillist'
|
9
|
+
autoload :Mail, 'timepad/mail'
|
5
10
|
autoload :Event, 'timepad/event'
|
6
11
|
autoload :Category, 'timepad/category'
|
7
12
|
autoload :Config, 'timepad/config'
|
8
|
-
|
13
|
+
autoload :Client, 'timepad/client'
|
9
14
|
extend Config
|
15
|
+
|
16
|
+
def self.maillist
|
17
|
+
client.maillist
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.mail
|
21
|
+
client.mail
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.category
|
25
|
+
client.category
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.event(id = nil)
|
29
|
+
event = client.event
|
30
|
+
id.nil? ? event : event.get(id)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.events(attrs ={})
|
34
|
+
event = client.event
|
35
|
+
event.get_list attrs
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.client(attrs = {})
|
39
|
+
if !@client
|
40
|
+
@client = Timepad::Client.new(attrs)
|
41
|
+
end
|
42
|
+
@client
|
43
|
+
end
|
44
|
+
|
10
45
|
end
|
data/lib/timepad/base.rb
CHANGED
@@ -3,21 +3,40 @@ require 'net/http'
|
|
3
3
|
|
4
4
|
module Timepad
|
5
5
|
class Base
|
6
|
-
def
|
6
|
+
def request(action, params = {})
|
7
7
|
uri = make_uri(action, params)
|
8
8
|
response = Net::HTTP.get(uri)
|
9
9
|
JSON.parse(response)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def make_query(params)
|
13
13
|
params.map{|key, value| value.nil? ? "" : "#{key}=#{value}"}.join('&')
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
params.merge!({'id' =>
|
16
|
+
def make_uri(action, params = {})
|
17
|
+
params.merge!({'id' => @client.id, 'code' => @client.key})
|
18
18
|
query = make_query(params)
|
19
|
-
object = self.name.split('::').last.downcase
|
19
|
+
object = self.class.name.split('::').last.downcase
|
20
20
|
URI("#{Timepad.endpoint.downcase}#{object}_#{action}?#{query}")
|
21
21
|
end
|
22
|
+
|
23
|
+
# Convert Array of Hash to Hash
|
24
|
+
#
|
25
|
+
# @param subscribers [Array]
|
26
|
+
# @return [Hash]
|
27
|
+
def subscribers_to_hash(subscribers)
|
28
|
+
i = 0
|
29
|
+
params = {}
|
30
|
+
subscribers.each do |subscriber|
|
31
|
+
next if subscriber[:email].empty?
|
32
|
+
%w(email name surnname middlename company phone comment).each do |key|
|
33
|
+
if subscriber[key.to_sym]
|
34
|
+
params[ "i#{i}_#{key}".to_sym ] = subscriber[key.to_sym]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
i += 1
|
38
|
+
end
|
39
|
+
params
|
40
|
+
end
|
22
41
|
end
|
23
42
|
end
|
data/lib/timepad/category.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
module Timepad
|
2
2
|
class Category < Base
|
3
|
+
def initialize(timepad_client)
|
4
|
+
@client = timepad_client
|
5
|
+
end
|
6
|
+
|
3
7
|
|
4
8
|
# Get all categories
|
5
9
|
#
|
6
10
|
# @return [Array]
|
7
|
-
def
|
8
|
-
request
|
11
|
+
def get_list
|
12
|
+
request 'getlist'
|
9
13
|
end
|
10
14
|
|
11
15
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Timepad
|
2
|
+
class Client
|
3
|
+
|
4
|
+
# Initalize new API
|
5
|
+
#
|
6
|
+
# @param attrs [Hash]
|
7
|
+
# @return [Timepad::Client]
|
8
|
+
def initialize(attrs = {})
|
9
|
+
attrs = Timepad.options.merge(attrs)
|
10
|
+
Config::VALID_OPTIONS_KEYS.each do |key|
|
11
|
+
instance_variable_set("@#{key}".to_sym, attrs[key])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return Maillist object
|
16
|
+
#
|
17
|
+
# @return [Timepad::Maillist]
|
18
|
+
def maillist
|
19
|
+
@maillist ||= Timepad::Maillist.new(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return Mail object
|
23
|
+
#
|
24
|
+
# @return [Timepad::Mail]
|
25
|
+
def mail
|
26
|
+
@mail ||= Timepad::Mail.new(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Category object
|
30
|
+
#
|
31
|
+
# @return [Timepad::Category]
|
32
|
+
def category
|
33
|
+
@category ||= Timepad::Category.new(self)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Event object
|
37
|
+
#
|
38
|
+
# @return [Timepad::Event]
|
39
|
+
def event
|
40
|
+
@event ||= Timepad::Event.new(self)
|
41
|
+
end
|
42
|
+
|
43
|
+
def key
|
44
|
+
@key
|
45
|
+
end
|
46
|
+
|
47
|
+
def id
|
48
|
+
@id
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/timepad/config.rb
CHANGED
@@ -24,6 +24,15 @@ module Timepad
|
|
24
24
|
self
|
25
25
|
end
|
26
26
|
|
27
|
+
# Create a hash of options and their values
|
28
|
+
#
|
29
|
+
# @return [Hash]
|
30
|
+
def options
|
31
|
+
options = {}
|
32
|
+
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
|
33
|
+
options
|
34
|
+
end
|
35
|
+
|
27
36
|
def reset
|
28
37
|
self.id = DEFAULT_ID
|
29
38
|
self.key = DEFAULT_KEY
|
data/lib/timepad/event.rb
CHANGED
@@ -1,28 +1,51 @@
|
|
1
1
|
module Timepad
|
2
2
|
class Event < Base
|
3
3
|
|
4
|
+
def initialize(timepad_client)
|
5
|
+
@client = timepad_client
|
6
|
+
end
|
7
|
+
|
4
8
|
# Get all events
|
5
9
|
#
|
6
10
|
# @param [Hash{cat_id => String, limit => String, order_by =>String}]
|
7
11
|
# @return [Array]
|
8
|
-
def
|
9
|
-
request
|
12
|
+
def get_list(attrs = {})
|
13
|
+
request 'getlist', attrs
|
10
14
|
end
|
11
15
|
|
12
16
|
# Get event by event_id
|
13
17
|
#
|
14
18
|
# @param [String] event_id
|
15
19
|
# @return [Array]
|
16
|
-
def
|
17
|
-
request
|
20
|
+
def get(event_id)
|
21
|
+
request 'get', :e_id => event_id
|
18
22
|
end
|
19
23
|
|
20
|
-
# Get event
|
24
|
+
# Get event members
|
21
25
|
#
|
22
26
|
# @params [String] event_id
|
23
27
|
# @return [Array]
|
24
|
-
def
|
25
|
-
|
28
|
+
def export(event_id, attrs = nil)
|
29
|
+
request_attrs = {:e_id => event_id}
|
30
|
+
request_attrs.merge!(attrs) unless attrs.nil?
|
31
|
+
request 'export', request_attrs
|
32
|
+
end
|
33
|
+
|
34
|
+
# Create event
|
35
|
+
#
|
36
|
+
# @params [Hash{name => String, }]
|
37
|
+
# @return [Array]
|
38
|
+
def create(attrs)
|
39
|
+
request 'create', attrs
|
26
40
|
end
|
41
|
+
|
42
|
+
# Register event member
|
43
|
+
#
|
44
|
+
# @params [Hash{e_id => String, re_id => String, mail => String}]
|
45
|
+
# @retur [Array]
|
46
|
+
def register(attrs)
|
47
|
+
request 'register', attrs
|
48
|
+
end
|
49
|
+
|
27
50
|
end
|
28
51
|
end
|
data/lib/timepad/mail.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Timepad
|
2
|
+
class Mail < Base
|
3
|
+
|
4
|
+
def initialize(timepad_client)
|
5
|
+
@client = timepad_client
|
6
|
+
end
|
7
|
+
|
8
|
+
# Create and send mail
|
9
|
+
#
|
10
|
+
# @param attrs [Hash] mail attributes
|
11
|
+
# @return [Array]
|
12
|
+
def create attrs
|
13
|
+
params = {}
|
14
|
+
params[:name] = attrs[:subject] if attrs.has_key?(:subject)
|
15
|
+
params[:text] = attrs[:text] if attrs.has_key?(:text)
|
16
|
+
params[:e_id] = attrs[:event] if attrs.has_key?(:event)
|
17
|
+
params[:reply_to] = attrs[:reply_to] if attrs.has_key?(:reply_to)
|
18
|
+
params[:template] = attrs[:template] if attrs.has_key?(:template)
|
19
|
+
params[:org_info] = attrs[:org_info] if attrs.has_key?(:org_info)
|
20
|
+
|
21
|
+
if attrs.has_key?(:subscribers)
|
22
|
+
i = 0
|
23
|
+
attrs[:subscribers].each do |email|
|
24
|
+
params["a#{i}".to_sym] = email
|
25
|
+
i += 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
attrs[:maillists] ||= []
|
30
|
+
if attrs.has_key?(:maillist)
|
31
|
+
attrs[:maillists] << attrs[:maillist]
|
32
|
+
end
|
33
|
+
|
34
|
+
i = 0
|
35
|
+
attrs[:maillists].each do |maillist_id|
|
36
|
+
params["m#{i}".to_sym] = maillist_id
|
37
|
+
i += 1
|
38
|
+
end
|
39
|
+
|
40
|
+
request 'create', params
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/lib/timepad/maillist.rb
CHANGED
@@ -1,20 +1,49 @@
|
|
1
1
|
module Timepad
|
2
2
|
class Maillist < Base
|
3
3
|
|
4
|
+
def initialize(timepad_client)
|
5
|
+
@client = timepad_client
|
6
|
+
end
|
7
|
+
|
4
8
|
# Get all maillists
|
5
9
|
#
|
6
10
|
# @return [Array]
|
7
|
-
def
|
8
|
-
request
|
11
|
+
def get_list
|
12
|
+
request 'getlist'
|
9
13
|
end
|
10
14
|
|
11
15
|
# Get maillist subscribers
|
12
16
|
#
|
13
|
-
# @param [String] maillist id
|
17
|
+
# @param maillist_id [String] maillist id
|
14
18
|
# @return [Array]
|
15
|
-
def
|
16
|
-
request
|
19
|
+
def get maillist_id
|
20
|
+
request 'get', :maillist => maillist_id
|
21
|
+
end
|
22
|
+
|
23
|
+
# Add maillist subscribers
|
24
|
+
#
|
25
|
+
# @param maillist_id [String] maillist id
|
26
|
+
# @param subscribers [Array]
|
27
|
+
def add_items maillist_id, subscribers
|
28
|
+
if subscribers.kind_of? Hash
|
29
|
+
subscribers = [subscribers]
|
30
|
+
end
|
31
|
+
|
32
|
+
params = subscribers_to_hash(subscribers)
|
33
|
+
params[:m_id] = maillist_id
|
34
|
+
|
35
|
+
request 'add_items', params
|
17
36
|
end
|
18
37
|
|
38
|
+
# Create maillist
|
39
|
+
#
|
40
|
+
# @param title [String] maillist title
|
41
|
+
# @param subscribers [Array] maillist initial subscribers
|
42
|
+
def create title, subscribers
|
43
|
+
params = subscribers_to_hash(subscribers)
|
44
|
+
params[:name] = title
|
45
|
+
|
46
|
+
request 'create', params
|
47
|
+
end
|
19
48
|
end
|
20
49
|
end
|
data/lib/timepad/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Timepad::BaseTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Timepad.configure do |config|
|
7
|
+
config.key = 'api_key'
|
8
|
+
config.id = '7912'
|
9
|
+
end
|
10
|
+
@client = Timepad::Client.new
|
11
|
+
@base = Timepad::Base.new
|
12
|
+
@base.instance_variable_set(:@client,@client)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_should_make_query
|
16
|
+
query = @base.make_query :a => 'b', :c => 'd'
|
17
|
+
|
18
|
+
assert_equal 'a=b&c=d', query
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_should_make_query_without_nil_value
|
22
|
+
query = @base.make_query :a => nil, :c => 'd'
|
23
|
+
|
24
|
+
assert_equal '&c=d', query
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_make_request
|
28
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}base_action")
|
29
|
+
.with(:query => {:code => Timepad.key, :id => Timepad.id, :param => 'value' })
|
30
|
+
.to_return(:body => '["test"]')
|
31
|
+
|
32
|
+
@base.request 'action', :param => 'value'
|
33
|
+
|
34
|
+
assert_requested(request)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
@@ -10,9 +10,13 @@ class Timepad::CategoryTest < MiniTest::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_should_get_categories
|
13
|
-
stub_http_request(:get, "#{Timepad.endpoint}category_getlist")
|
13
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}category_getlist")
|
14
14
|
.with(:query => {:code => Timepad.key, :id => Timepad.id})
|
15
|
-
.to_return(:body => '[]')
|
16
|
-
|
15
|
+
.to_return(:body => '["test"]')
|
16
|
+
|
17
|
+
result = Timepad.category.get_list
|
18
|
+
|
19
|
+
assert_requested(request)
|
20
|
+
assert_equal result, ["test"]
|
17
21
|
end
|
18
22
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Timepad::ClientTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Timepad.configure do |config|
|
7
|
+
config.key = 'api_key'
|
8
|
+
config.id = '7912'
|
9
|
+
end
|
10
|
+
@client = Timepad::Client.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_get_client
|
14
|
+
assert_kind_of Timepad::Client, @client
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_get_maillist
|
18
|
+
maillist = @client.maillist
|
19
|
+
assert_kind_of Timepad::Maillist, maillist
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_get_mail
|
23
|
+
mail = @client.mail
|
24
|
+
assert_kind_of Timepad::Mail, mail
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_get_category
|
28
|
+
category = @client.category
|
29
|
+
assert_kind_of Timepad::Category, category
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_get_event
|
33
|
+
event = @client.event
|
34
|
+
assert_kind_of Timepad::Event, event
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_get_key
|
38
|
+
key = @client.key
|
39
|
+
assert_equal 'api_key', @client.key
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_should_get_id
|
43
|
+
key = @client.id
|
44
|
+
assert_equal '7912', @client.id
|
45
|
+
end
|
46
|
+
end
|
data/test/timepad/event_test.rb
CHANGED
@@ -10,34 +10,84 @@ class Timepad::EventTest < MiniTest::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_should_get_events
|
13
|
-
stub_http_request(:get, "#{Timepad.endpoint}event_getlist")
|
14
|
-
.with(:query => {:code => Timepad.key, :id => Timepad.id})
|
15
|
-
.to_return(:body => '[]')
|
16
|
-
|
13
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}event_getlist")
|
14
|
+
.with(:query => {:code => Timepad.key, :id => Timepad.id, :limit => 1, :order_by => 'begin'})
|
15
|
+
.to_return(:body => '["test"]')
|
16
|
+
|
17
|
+
result = Timepad.event.get_list :limit => 1, :order_by => :begin
|
18
|
+
|
19
|
+
assert_requested(request)
|
20
|
+
assert_equal result, ["test"]
|
17
21
|
end
|
18
22
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
Timepad
|
23
|
+
def test_should_get_events_too
|
24
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}event_getlist")
|
25
|
+
.with(:query => {:code => Timepad.key, :id => Timepad.id, :limit => 1, :order_by => 'begin'})
|
26
|
+
.to_return(:body => '["test"]')
|
27
|
+
|
28
|
+
result = Timepad.events :limit => 1, :order_by => :begin
|
29
|
+
|
30
|
+
assert_requested(request)
|
31
|
+
assert_equal result, ["test"]
|
25
32
|
end
|
26
33
|
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
def test_should_get_event
|
35
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}event_get")
|
36
|
+
.with(:query => {:code => Timepad.key, :id => Timepad.id, :e_id => 1})
|
37
|
+
.to_return(:body => '["test"]')
|
38
|
+
result = Timepad.event 1
|
39
|
+
|
40
|
+
assert_requested(request)
|
41
|
+
assert_equal result, ["test"]
|
33
42
|
end
|
34
43
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
44
|
+
def test_should_get_event_to
|
45
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}event_get")
|
46
|
+
.with(:query => {:code => Timepad.key, :id => Timepad.id, :e_id => 1})
|
47
|
+
.to_return(:body => '["test"]')
|
48
|
+
result = Timepad.event.get 1
|
49
|
+
|
50
|
+
assert_requested(request)
|
51
|
+
assert_equal result, ["test"]
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_should_export_event_members
|
55
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}event_export")
|
56
|
+
.with(:query => {:code => Timepad.key, :id => Timepad.id, :e_id => 1})
|
57
|
+
.to_return(:body => '["test"]')
|
58
|
+
result = Timepad.event.export 1
|
59
|
+
|
60
|
+
assert_requested(request)
|
61
|
+
assert_equal result, ["test"]
|
41
62
|
end
|
42
63
|
|
64
|
+
def test_should_export_event_member
|
65
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}event_export")
|
66
|
+
.with(:query => {:code => Timepad.key, :id => Timepad.id, :e_id => 1, :r_id => 2})
|
67
|
+
.to_return(:body => '["test"]')
|
68
|
+
result = Timepad.event.export 1, :r_id => 2
|
69
|
+
|
70
|
+
assert_requested(request)
|
71
|
+
assert_equal result, ["test"]
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_should_create_event
|
75
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}event_create")
|
76
|
+
.with(:query => {:code => Timepad.key, :id => Timepad.id, :name => 'Name', :start_date => '2011-02-27'})
|
77
|
+
.to_return(:body => '["test"]')
|
78
|
+
result = Timepad.event.create :name => 'Name', :start_date => '2011-02-27'
|
79
|
+
|
80
|
+
assert_requested(request)
|
81
|
+
assert_equal result, ["test"]
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_should_register_event_member
|
85
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}event_register")
|
86
|
+
.with(:query => {:code => Timepad.key, :id => Timepad.id, :e_id => 1, :re_id => 2})
|
87
|
+
.to_return(:body => '["test"]')
|
88
|
+
result = Timepad.event.register :e_id => 1, :re_id => 2
|
89
|
+
|
90
|
+
assert_requested(request)
|
91
|
+
assert_equal result, ["test"]
|
92
|
+
end
|
43
93
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Timepad::MailTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Timepad.configure do |config|
|
7
|
+
config.key = 'api_key'
|
8
|
+
config.id = '7912'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_create_mail
|
13
|
+
request = stub_request(:get, "http://timepad.ru/api/mail_create?a0=a@a.a&a1=b@b.b&code=api_key&id=7912&m0=1&m1=2&name=subject&text=text").to_return(:body => '["test"]')
|
14
|
+
result = Timepad.mail.create :subject => 'subject', :text => 'text', :maillists => [1,2], :subscribers => ['a@a.a', 'b@b.b']
|
15
|
+
|
16
|
+
assert_requested(request)
|
17
|
+
assert_equal result, ["test"]
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -9,10 +9,50 @@ class Timepad::MaillistTest < MiniTest::Unit::TestCase
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
stub_http_request(:get, "#{Timepad.endpoint}maillist_getlist")
|
12
|
+
def test_should_get_maillists
|
13
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}maillist_getlist")
|
14
14
|
.with(:query => {:code => Timepad.key, :id => Timepad.id})
|
15
|
-
.to_return(:body => '[]')
|
16
|
-
|
15
|
+
.to_return(:body => '["test"]')
|
16
|
+
|
17
|
+
result = Timepad.maillist.get_list
|
18
|
+
|
19
|
+
assert_requested(request)
|
20
|
+
assert_equal result, ["test"]
|
17
21
|
end
|
22
|
+
|
23
|
+
def test_should_get_maillist
|
24
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}maillist_get")
|
25
|
+
.with(:query => {:code => Timepad.key, :id => Timepad.id, :maillist => 'test'})
|
26
|
+
.to_return(:body => '["test"]')
|
27
|
+
|
28
|
+
result = Timepad.maillist.get 'test'
|
29
|
+
|
30
|
+
assert_requested(request)
|
31
|
+
assert_equal result, ["test"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_add_subscribers
|
35
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}maillist_add_items")
|
36
|
+
.with(:query => {:code => Timepad.key, :id => Timepad.id, :m_id => 'test', :i0_email => 'test@example.com'})
|
37
|
+
.to_return(:body => '["test"]')
|
38
|
+
|
39
|
+
result = Timepad.maillist.add_items 'test', [{:email => 'test@example.com'}]
|
40
|
+
|
41
|
+
assert_requested(request)
|
42
|
+
assert_equal result, ["test"]
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_create_maillist
|
46
|
+
request = stub_http_request(:get, "#{Timepad.endpoint}maillist_create")
|
47
|
+
.with(:query => {:code => Timepad.key, :id => Timepad.id, :name => 'test', :i0_email => 'test@example.com'})
|
48
|
+
.to_return(:body => '["test"]')
|
49
|
+
|
50
|
+
result = Timepad.maillist.create 'test', [{:email => 'test@example.com'}]
|
51
|
+
|
52
|
+
assert_requested(request)
|
53
|
+
assert_equal result, ["test"]
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
|
18
58
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TimepadTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
Timepad.configure do |config|
|
7
|
+
config.key = 'api_key'
|
8
|
+
config.id = '7912'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_get_client_instance
|
13
|
+
client = Timepad.client
|
14
|
+
assert_kind_of Timepad::Client, client
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_should_get_mailist_instance
|
18
|
+
maillist = Timepad.maillist
|
19
|
+
assert_kind_of Timepad::Maillist, maillist
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_get_mail_instance
|
23
|
+
mail = Timepad.mail
|
24
|
+
assert_kind_of Timepad::Mail, mail
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_get_category_instance
|
28
|
+
category = Timepad.category
|
29
|
+
assert_kind_of Timepad::Category, category
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_get_event_instance
|
33
|
+
event = Timepad.event
|
34
|
+
assert_kind_of Timepad::Event, event
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/timepad.gemspec
CHANGED
@@ -6,7 +6,8 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["subbota@gmail.com"]
|
7
7
|
gem.description = %q{Gem that provide access to timepad.ru api}
|
8
8
|
gem.summary = %q{See description}
|
9
|
-
gem.homepage = "
|
9
|
+
gem.homepage = ""
|
10
|
+
gem.add_dependency('activesupport')
|
10
11
|
|
11
12
|
gem.files = `git ls-files`.split("\n")
|
12
13
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timepad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
description: Gem that provide access to timepad.ru api
|
15
31
|
email:
|
16
32
|
- subbota@gmail.com
|
@@ -19,23 +35,29 @@ extensions: []
|
|
19
35
|
extra_rdoc_files: []
|
20
36
|
files:
|
21
37
|
- .gitignore
|
38
|
+
- .travis.yml
|
22
39
|
- Gemfile
|
23
40
|
- README.md
|
24
|
-
- README.rdoc
|
25
41
|
- Rakefile
|
26
42
|
- lib/timepad.rb
|
27
43
|
- lib/timepad/base.rb
|
28
44
|
- lib/timepad/category.rb
|
45
|
+
- lib/timepad/client.rb
|
29
46
|
- lib/timepad/config.rb
|
30
47
|
- lib/timepad/event.rb
|
48
|
+
- lib/timepad/mail.rb
|
31
49
|
- lib/timepad/maillist.rb
|
32
50
|
- lib/timepad/version.rb
|
33
51
|
- test/test_helper.rb
|
52
|
+
- test/timepad/base_test.rb
|
34
53
|
- test/timepad/category_test.rb
|
54
|
+
- test/timepad/client_test.rb
|
35
55
|
- test/timepad/event_test.rb
|
56
|
+
- test/timepad/mail_test.rb
|
36
57
|
- test/timepad/maillist_test.rb
|
58
|
+
- test/timepad_test.rb
|
37
59
|
- timepad.gemspec
|
38
|
-
homepage:
|
60
|
+
homepage: ''
|
39
61
|
licenses: []
|
40
62
|
post_install_message:
|
41
63
|
rdoc_options: []
|
@@ -61,7 +83,11 @@ specification_version: 3
|
|
61
83
|
summary: See description
|
62
84
|
test_files:
|
63
85
|
- test/test_helper.rb
|
86
|
+
- test/timepad/base_test.rb
|
64
87
|
- test/timepad/category_test.rb
|
88
|
+
- test/timepad/client_test.rb
|
65
89
|
- test/timepad/event_test.rb
|
90
|
+
- test/timepad/mail_test.rb
|
66
91
|
- test/timepad/maillist_test.rb
|
92
|
+
- test/timepad_test.rb
|
67
93
|
has_rdoc:
|
data/README.rdoc
DELETED