sched 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
- data/{README.rdoc → README.md} +2 -2
- data/lib/sched/client.rb +49 -35
- data/lib/sched/event.rb +20 -22
- data/lib/sched/version.rb +1 -3
- data/lib/sched.rb +4 -4
- metadata +9 -31
- data/.gitignore +0 -21
- data/Gemfile +0 -5
- data/Gemfile.lock +0 -20
- data/LICENSE +0 -20
- data/sched.gemspec +0 -25
- data/test/helper.rb +0 -10
- data/test/test_sched.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a101c3e618eec8f111d51642695e6d38452d3d63
|
4
|
+
data.tar.gz: cfadcf4667315d5bc00719ce1585350f99966bdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 281baf4229bb7e1794b1a77420b725a579f6607d4851e824a8644caac250ea831e8ffac70196a69ee1952640eb7ed5c5e349dcc296ce46c81a964628cb8ca016
|
7
|
+
data.tar.gz: 8281be80bcc4fab4c4208f186fe0c52a172d94d6fc7bfee3f1858cca7eb7cd6fb56668828cce988afede58e669113f5189492319472df6ad6912ed54ecf561d8
|
data/{README.rdoc → README.md}
RENAMED
data/lib/sched/client.rb
CHANGED
@@ -2,59 +2,73 @@ module Sched
|
|
2
2
|
class Client
|
3
3
|
attr_accessor :conference, :api_key
|
4
4
|
def initialize(conference, api_key)
|
5
|
-
@conference
|
5
|
+
@conference = conference
|
6
|
+
@api_key = api_key
|
6
7
|
end
|
7
8
|
|
8
9
|
def event(session_key)
|
9
10
|
event = Sched::Event.new(session_key, self)
|
10
|
-
if event.exists?
|
11
|
-
event = self.events.select{|e| e.session_key == session_key}.first
|
12
|
-
end
|
11
|
+
event = events.find { |e| e.session_key == session_key } if event.exists?
|
13
12
|
event
|
14
13
|
end
|
15
14
|
|
16
15
|
def events
|
17
|
-
|
18
|
-
results = FasterCSV.parse(request('session/list', nil, :get))
|
19
|
-
|
20
|
-
attributes = results.shift.map do |a|
|
21
|
-
a.strip.gsub(/[\u0080-\u00ff]/, "").gsub(/^event_/, "session_").to_sym
|
22
|
-
end
|
23
|
-
|
24
|
-
@events = results.map do |row|
|
25
|
-
row_hash = {}
|
26
|
-
attributes.each_with_index do |a, i|
|
27
|
-
row_hash[a] = row[i]
|
28
|
-
end
|
29
|
-
Sched::Event.new(row_hash[:session_key], self).configure(row_hash)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
@events
|
16
|
+
@events ||= parse_sessions(CSV.parse(request("session/list", nil, :get)))
|
33
17
|
end
|
34
18
|
|
35
19
|
def api_url
|
36
20
|
"http://#{@conference}.sched.org/api"
|
37
21
|
end
|
38
22
|
|
39
|
-
def request(
|
23
|
+
def request(path, data = {}, method = :post)
|
40
24
|
data ||= {}
|
41
|
-
data
|
42
|
-
url = "#{api_url}/#{sub_url}"
|
43
|
-
output = nil
|
25
|
+
data[:api_key] = @api_key
|
44
26
|
if method == :post
|
45
|
-
|
46
|
-
c = Curl::Easy.new(url)
|
47
|
-
c.headers["User-Agent"] = "sched-gem"
|
48
|
-
c.http_post(post_fields)
|
49
|
-
output = c.body_str
|
27
|
+
post_request(path, data)
|
50
28
|
elsif method == :get
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
29
|
+
get_request(path, data)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def curl_client(path)
|
36
|
+
c = Curl::Easy.new("#{api_url}/#{path}")
|
37
|
+
c.headers["User-Agent"] = "sched-gem"
|
38
|
+
c
|
39
|
+
end
|
40
|
+
|
41
|
+
def full_url(path)
|
42
|
+
"#{api_url}/#{path}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_request(path, data)
|
46
|
+
get_attributes = data.map { |key, value| "#{key}=#{value}" }.join("&")
|
47
|
+
c = curl_client("#{path}?#{get_attributes}")
|
48
|
+
c.perform
|
49
|
+
c.body_str
|
50
|
+
end
|
51
|
+
|
52
|
+
def parse_sessions(results)
|
53
|
+
attributes = results.shift.map do |a|
|
54
|
+
a.strip.gsub(/[\u0080-\u00ff]/, "").gsub(/^event_/, "session_").to_sym
|
55
|
+
end
|
56
|
+
results.map do |row|
|
57
|
+
row_hash = {}
|
58
|
+
attributes.each_with_index do |a, i|
|
59
|
+
row_hash[a] = row[i]
|
60
|
+
end
|
61
|
+
Sched::Event.new(row_hash[:session_key], self).configure(row_hash)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def post_request(path, data)
|
66
|
+
post_fields = data.map do |key, value|
|
67
|
+
Curl::PostField.content(key.to_s, value)
|
56
68
|
end
|
57
|
-
|
69
|
+
c = curl_client(path)
|
70
|
+
c.http_post(post_fields)
|
71
|
+
c.body_str
|
58
72
|
end
|
59
73
|
end
|
60
74
|
end
|
data/lib/sched/event.rb
CHANGED
@@ -4,25 +4,24 @@ module Sched
|
|
4
4
|
# Required
|
5
5
|
:session_key, :name, :session_start, :session_end, :session_type,
|
6
6
|
# Optional
|
7
|
-
:session_subtype, :description, :panelists, :url, :media_url, :venue,
|
8
|
-
|
9
|
-
|
7
|
+
:session_subtype, :description, :panelists, :url, :media_url, :venue,
|
8
|
+
:address, :map, :tags, :active
|
9
|
+
].freeze
|
10
|
+
SCHED_ATTRIBUTES.each { |attribute| attr_accessor attribute }
|
10
11
|
attr_accessor :client
|
11
12
|
|
12
|
-
def initialize(session_key, client=nil)
|
13
|
+
def initialize(session_key, client = nil)
|
13
14
|
@session_key = session_key
|
14
15
|
@client = client
|
15
16
|
end
|
16
17
|
|
17
18
|
def get_attribute(key)
|
18
|
-
|
19
|
+
send(key.to_s)
|
19
20
|
end
|
20
21
|
|
21
|
-
def configure(options={})
|
22
|
+
def configure(options = {})
|
22
23
|
options.each do |key, value|
|
23
|
-
if SCHED_ATTRIBUTES.include?(key)
|
24
|
-
self.send("#{key.to_s}=", value)
|
25
|
-
end
|
24
|
+
send("#{key}=", value) if SCHED_ATTRIBUTES.include?(key)
|
26
25
|
end
|
27
26
|
self
|
28
27
|
end
|
@@ -30,38 +29,37 @@ module Sched
|
|
30
29
|
def data
|
31
30
|
data = {}
|
32
31
|
SCHED_ATTRIBUTES.each do |attribute|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
32
|
+
next if get_attribute(attribute).nil?
|
33
|
+
value = get_attribute(attribute)
|
34
|
+
value = "Y" if value == true
|
35
|
+
value = "N" if value == false
|
36
|
+
data[attribute] = value
|
39
37
|
end
|
40
38
|
data
|
41
39
|
end
|
42
40
|
|
43
41
|
def save
|
44
|
-
if
|
45
|
-
|
42
|
+
if exists?
|
43
|
+
update
|
46
44
|
else
|
47
|
-
|
45
|
+
create
|
48
46
|
end
|
49
47
|
end
|
50
48
|
|
51
49
|
def create
|
52
|
-
|
50
|
+
client.request("session/add", data)
|
53
51
|
end
|
54
52
|
|
55
53
|
def update
|
56
|
-
|
54
|
+
client.request("session/mod", data)
|
57
55
|
end
|
58
56
|
|
59
57
|
def exists?
|
60
|
-
client.events.map
|
58
|
+
client.events.map(&:session_key).include?(session_key) ? true : false
|
61
59
|
end
|
62
60
|
|
63
61
|
def destroy
|
64
|
-
|
62
|
+
client.request("session/del", session_key: session_key)
|
65
63
|
end
|
66
64
|
end
|
67
65
|
end
|
data/lib/sched/version.rb
CHANGED
data/lib/sched.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "csv"
|
2
|
+
require "curb"
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "sched/client"
|
5
|
+
require "sched/event"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sched
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Inge Jørgensen
|
@@ -14,48 +14,27 @@ dependencies:
|
|
14
14
|
name: curb
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.9.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: fastercsv
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
26
|
+
version: 0.9.3
|
41
27
|
description: SCHED* (http://sched.org) API client library for Ruby
|
42
28
|
email: inge@manualdesign.no
|
43
29
|
executables: []
|
44
30
|
extensions: []
|
45
31
|
extra_rdoc_files: []
|
46
32
|
files:
|
47
|
-
-
|
48
|
-
- Gemfile
|
49
|
-
- Gemfile.lock
|
50
|
-
- LICENSE
|
51
|
-
- README.rdoc
|
33
|
+
- README.md
|
52
34
|
- lib/sched.rb
|
53
35
|
- lib/sched/client.rb
|
54
36
|
- lib/sched/event.rb
|
55
37
|
- lib/sched/version.rb
|
56
|
-
- sched.gemspec
|
57
|
-
- test/helper.rb
|
58
|
-
- test/test_sched.rb
|
59
38
|
homepage: http://github.com/elektronaut/sched
|
60
39
|
licenses:
|
61
40
|
- MIT
|
@@ -79,7 +58,6 @@ rubyforge_project:
|
|
79
58
|
rubygems_version: 2.4.5
|
80
59
|
signing_key:
|
81
60
|
specification_version: 4
|
82
|
-
summary: SCHED*
|
83
|
-
test_files:
|
84
|
-
|
85
|
-
- test/test_sched.rb
|
61
|
+
summary: SCHED* API client library for Ruby
|
62
|
+
test_files: []
|
63
|
+
has_rdoc:
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2010 Manual design
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/sched.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
$:.push File.expand_path("../lib", __FILE__)
|
4
|
-
require "sched/version"
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = 'sched'
|
8
|
-
s.version = Sched::VERSION
|
9
|
-
s.date = '2014-01-20'
|
10
|
-
s.summary = "SCHED* (http://sched.org) API client library for Ruby"
|
11
|
-
s.description = "SCHED* (http://sched.org) API client library for Ruby"
|
12
|
-
s.authors = ["Inge Jørgensen"]
|
13
|
-
s.email = 'inge@manualdesign.no'
|
14
|
-
s.homepage = 'http://github.com/elektronaut/sched'
|
15
|
-
s.license = 'MIT'
|
16
|
-
s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
|
17
|
-
|
18
|
-
s.files = `git ls-files`.split("\n")
|
19
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
-
s.require_paths = ["lib"]
|
22
|
-
|
23
|
-
s.add_dependency 'curb'
|
24
|
-
s.add_dependency 'fastercsv'
|
25
|
-
end
|
data/test/helper.rb
DELETED