sched 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23c303ccaa1abf47d80c0e66ecdcd5044e7acfa5
4
- data.tar.gz: 637269c9b81d68c09031db277fdf2b56cd243ae5
3
+ metadata.gz: a101c3e618eec8f111d51642695e6d38452d3d63
4
+ data.tar.gz: cfadcf4667315d5bc00719ce1585350f99966bdb
5
5
  SHA512:
6
- metadata.gz: 1350978bd368d155e41fffae95964fcd9b0b004c07ad901a6e3830e12d2f77ca61d9a77d8df2db8c579364f8b98cea4df3e8fc472a361d9751b2eb69243396e3
7
- data.tar.gz: 934cc6c4eaa5c21d29eec2364b7e644b9cf17a3817ecb960a30cff39c6eb9edb1c85360f5e7e356c6dbe4519887dbeb8cd8a4fe8f35ff58193acdb7c7a5f1960
6
+ metadata.gz: 281baf4229bb7e1794b1a77420b725a579f6607d4851e824a8644caac250ea831e8ffac70196a69ee1952640eb7ed5c5e349dcc296ce46c81a964628cb8ca016
7
+ data.tar.gz: 8281be80bcc4fab4c4208f186fe0c52a172d94d6fc7bfee3f1858cca7eb7cd6fb56668828cce988afede58e669113f5189492319472df6ad6912ed54ecf561d8
@@ -1,7 +1,7 @@
1
- = SCHED*
1
+ # SCHED*
2
2
 
3
3
  Thirt-party Ruby client library for the SCHED* API. See http://sched.org
4
4
 
5
- == Copyright
5
+ ## Copyright
6
6
 
7
7
  Copyright (c) 2010 Manual design. See LICENSE for details.
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, @api_key = conference, api_key
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
- unless @events
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(sub_url, data={}, method = :post)
23
+ def request(path, data = {}, method = :post)
40
24
  data ||= {}
41
- data.merge!({:api_key => @api_key})
42
- url = "#{api_url}/#{sub_url}"
43
- output = nil
25
+ data[:api_key] = @api_key
44
26
  if method == :post
45
- post_fields = data.map{|key, value| Curl::PostField.content(key.to_s, value)}
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
- get_attributes = data.map{|key, value| "#{key}=#{value}" }.join("&")
52
- c = Curl::Easy.new("#{url}?#{get_attributes}")
53
- c.headers["User-Agent"] = "sched-gem"
54
- c.perform
55
- output = c.body_str
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
- output
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, :address, :map, :tags, :active
8
- ]
9
- SCHED_ATTRIBUTES.each{ |attribute| attr_accessor attribute }
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
- self.send("#{key}")
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
- unless self.get_attribute(attribute) === nil
34
- value = self.get_attribute(attribute)
35
- value = 'Y' if value === true
36
- value = 'N' if value === false
37
- data[attribute] = value
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 self.exists?
45
- self.update
42
+ if exists?
43
+ update
46
44
  else
47
- self.create
45
+ create
48
46
  end
49
47
  end
50
48
 
51
49
  def create
52
- self.client.request('session/add', self.data)
50
+ client.request("session/add", data)
53
51
  end
54
52
 
55
53
  def update
56
- self.client.request('session/mod', self.data)
54
+ client.request("session/mod", data)
57
55
  end
58
56
 
59
57
  def exists?
60
- client.events.map{|e| e.session_key}.include?(self.session_key) ? true : false
58
+ client.events.map(&:session_key).include?(session_key) ? true : false
61
59
  end
62
60
 
63
61
  def destroy
64
- self.client.request('session/del', {:session_key => self.session_key})
62
+ client.request("session/del", session_key: session_key)
65
63
  end
66
64
  end
67
65
  end
data/lib/sched/version.rb CHANGED
@@ -1,5 +1,3 @@
1
1
  module Sched
2
- unless Sched.const_defined?('VERSION')
3
- VERSION = "0.1.6"
4
- end
2
+ VERSION = "0.1.7".freeze unless Sched.const_defined?("VERSION")
5
3
  end
data/lib/sched.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'curb'
2
- require 'fastercsv'
1
+ require "csv"
2
+ require "curb"
3
3
 
4
- require 'sched/client'
5
- require 'sched/event'
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.6
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: '0'
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: '0'
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
- - ".gitignore"
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* (http://sched.org) API client library for Ruby
83
- test_files:
84
- - test/helper.rb
85
- - test/test_sched.rb
61
+ summary: SCHED* API client library for Ruby
62
+ test_files: []
63
+ has_rdoc:
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
data/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem "rake"
data/Gemfile.lock DELETED
@@ -1,20 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- sched (0.1.6)
5
- curb
6
- fastercsv
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- curb (0.8.8)
12
- fastercsv (1.5.5)
13
- rake (10.4.2)
14
-
15
- PLATFORMS
16
- ruby
17
-
18
- DEPENDENCIES
19
- rake
20
- sched!
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
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'sched'
8
-
9
- class Test::Unit::TestCase
10
- end
data/test/test_sched.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestSched < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end