timepad 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ .yardoc
9
+ _yardoc
10
+ doc
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ *.sassc
15
+ .sass-cache
16
+ capybara-*.html
17
+ .rspec
18
+ log/*
19
+ test/tmp
20
+ test/version_tmp
21
+ tmp
22
+ *.orig
23
+ rerun.txt
24
+ pickle-email-*.html
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in timepad.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'webmock'
8
+ gem 'json'
9
+ gem 'turn'
10
+ gem 'minitest'
11
+ end
@@ -0,0 +1,4 @@
1
+ timepad
2
+ =======
3
+
4
+ api
@@ -0,0 +1,4 @@
1
+ timepad
2
+ =======
3
+
4
+ api
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ module Timepad
2
+ autoload :Base, 'timepad/base'
3
+ autoload :Version, 'timepad/version'
4
+ autoload :Maillist, 'timepad/maillist'
5
+ autoload :Event, 'timepad/event'
6
+ autoload :Category, 'timepad/category'
7
+ autoload :Config, 'timepad/config'
8
+
9
+ extend Config
10
+ end
@@ -0,0 +1,23 @@
1
+ require 'json'
2
+ require 'net/http'
3
+
4
+ module Timepad
5
+ class Base
6
+ def self.request(action, params = {})
7
+ uri = make_uri(action, params)
8
+ response = Net::HTTP.get(uri)
9
+ JSON.parse(response)
10
+ end
11
+
12
+ def self.make_query(params)
13
+ params.map{|key, value| value.nil? ? "" : "#{key}=#{value}"}.join('&')
14
+ end
15
+
16
+ def self.make_uri(action, params = {})
17
+ params.merge!({'id' => Timepad.id, 'code' => Timepad.key})
18
+ query = make_query(params)
19
+ object = self.name.split('::').last.downcase
20
+ URI("#{Timepad.endpoint.downcase}#{object}_#{action}?#{query}")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ module Timepad
2
+ class Category < Base
3
+
4
+ # Get all categories
5
+ #
6
+ # @return [Array]
7
+ def self.get_list
8
+ request('getlist')
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ module Timepad
2
+ module Config
3
+
4
+ DEFAULT_ENDPOINT = 'http://timepad.ru/api/'
5
+
6
+ DEFAULT_ID = nil
7
+
8
+ DEFAULT_KEY = nil
9
+
10
+ VALID_OPTIONS_KEYS = [
11
+ :id,
12
+ :key,
13
+ :endpoint
14
+ ]
15
+
16
+ attr_accessor *VALID_OPTIONS_KEYS
17
+
18
+ def self.extended(base)
19
+ base.reset
20
+ end
21
+
22
+ def configure
23
+ yield self
24
+ self
25
+ end
26
+
27
+ def reset
28
+ self.id = DEFAULT_ID
29
+ self.key = DEFAULT_KEY
30
+ self.endpoint = DEFAULT_ENDPOINT
31
+ self
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,28 @@
1
+ module Timepad
2
+ class Event < Base
3
+
4
+ # Get all events
5
+ #
6
+ # @param [Hash{cat_id => String, limit => String, order_by =>String}]
7
+ # @return [Array]
8
+ def self.get_list params = {}
9
+ request('getlist', params)
10
+ end
11
+
12
+ # Get event by event_id
13
+ #
14
+ # @param [String] event_id
15
+ # @return [Array]
16
+ def self.get event_id
17
+ request('get', :e_id => event_id)
18
+ end
19
+
20
+ # Get event subscribers
21
+ #
22
+ # @params [String] event_id
23
+ # @return [Array]
24
+ def self.export event_id
25
+ request('export', :e_id => event_id)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ module Timepad
2
+ class Maillist < Base
3
+
4
+ # Get all maillists
5
+ #
6
+ # @return [Array]
7
+ def self.get_list
8
+ request('getlist')
9
+ end
10
+
11
+ # Get maillist subscribers
12
+ #
13
+ # @param [String] maillist id
14
+ # @return [Array]
15
+ def self.get maillist_id
16
+ request('get', :maillist => maillist_id)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Timepad
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'minitest/unit'
2
+ require 'webmock/minitest'
3
+ require 'timepad'
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class Timepad::CategoryTest < 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_categories
13
+ stub_http_request(:get, "#{Timepad.endpoint}category_getlist")
14
+ .with(:query => {:code => Timepad.key, :id => Timepad.id})
15
+ .to_return(:body => '[]')
16
+ Timepad::Category.get_list
17
+ end
18
+ end
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+
3
+ class Timepad::EventTest < 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_events
13
+ stub_http_request(:get, "#{Timepad.endpoint}event_getlist")
14
+ .with(:query => {:code => Timepad.key, :id => Timepad.id})
15
+ .to_return(:body => '[]')
16
+ Timepad::Event.get_list
17
+ end
18
+
19
+ def test_should_get_events_by_category
20
+ category_id = 1
21
+ stub_http_request(:get, "#{Timepad.endpoint}event_getlist")
22
+ .with(:query => {:code => Timepad.key, :id => Timepad.id, :cat_id => category_id})
23
+ .to_return(:body => '[]')
24
+ Timepad::Event.get_list :cat_id => category_id
25
+ end
26
+
27
+ def test_shoul_get_event
28
+ event_id = 1
29
+ stub_http_request(:get, "#{Timepad.endpoint}event_get")
30
+ .with(:query => {:code => Timepad.key, :id => Timepad.id, :e_id => event_id})
31
+ .to_return(:body => '[]')
32
+ Timepad::Event.get event_id
33
+ end
34
+
35
+ def test_shoul_get_event_subscribers
36
+ event_id = 1
37
+ stub_http_request(:get, "#{Timepad.endpoint}event_export")
38
+ .with(:query => {:code => Timepad.key, :id => Timepad.id, :e_id => event_id})
39
+ .to_return(:body => '[]')
40
+ Timepad::Event.export event_id
41
+ end
42
+
43
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class Timepad::MaillistTest < 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_mailists
13
+ stub_http_request(:get, "#{Timepad.endpoint}maillist_getlist")
14
+ .with(:query => {:code => Timepad.key, :id => Timepad.id})
15
+ .to_return(:body => '[]')
16
+ Timepad::Maillist.get_list
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/timepad/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Andrey Subbota"]
6
+ gem.email = ["subbota@gmail.com"]
7
+ gem.description = %q{Gem that provide access to timepad.ru api}
8
+ gem.summary = %q{See description}
9
+ gem.homepage = "https://github.com/kaize/timepad/"
10
+
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "timepad"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Timepad::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timepad
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrey Subbota
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-29 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Gem that provide access to timepad.ru api
15
+ email:
16
+ - subbota@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - README.md
24
+ - README.rdoc
25
+ - Rakefile
26
+ - lib/timepad.rb
27
+ - lib/timepad/base.rb
28
+ - lib/timepad/category.rb
29
+ - lib/timepad/config.rb
30
+ - lib/timepad/event.rb
31
+ - lib/timepad/maillist.rb
32
+ - lib/timepad/version.rb
33
+ - test/test_helper.rb
34
+ - test/timepad/category_test.rb
35
+ - test/timepad/event_test.rb
36
+ - test/timepad/maillist_test.rb
37
+ - timepad.gemspec
38
+ homepage: https://github.com/kaize/timepad/
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.23
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: See description
62
+ test_files:
63
+ - test/test_helper.rb
64
+ - test/timepad/category_test.rb
65
+ - test/timepad/event_test.rb
66
+ - test/timepad/maillist_test.rb
67
+ has_rdoc: