rabbit 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/Rakefile +46 -12
  2. data/data/locale/en/LC_MESSAGES/rabbit.mo +0 -0
  3. data/data/locale/fr/LC_MESSAGES/rabbit.mo +0 -0
  4. data/data/locale/ja/LC_MESSAGES/rabbit.mo +0 -0
  5. data/doc/_config.yml +3 -3
  6. data/doc/_layouts/en.html +10 -0
  7. data/doc/_layouts/ja.html +10 -0
  8. data/doc/css/rabbit.css +25 -4
  9. data/doc/en/index.rd +1 -1
  10. data/doc/en/news.rd +46 -0
  11. data/doc/images/rabbit-slide-show-logo.png +0 -0
  12. data/doc/images/rabbit-slide-show-logo.svg +597 -0
  13. data/doc/images/screenshots/en/blue-circle-raw.png +0 -0
  14. data/doc/images/screenshots/en/blue-circle.png +0 -0
  15. data/doc/images/screenshots/en/clear-blue-raw.png +0 -0
  16. data/doc/images/screenshots/en/clear-blue.png +0 -0
  17. data/doc/images/screenshots/en/cozmixng-raw.png +0 -0
  18. data/doc/images/screenshots/en/cozmixng.png +0 -0
  19. data/doc/images/screenshots/en/dark-gradation-raw.png +0 -0
  20. data/doc/images/screenshots/en/dark-gradation.png +0 -0
  21. data/doc/images/screenshots/en/day-white-raw.png +0 -0
  22. data/doc/images/screenshots/en/day-white.png +0 -0
  23. data/doc/images/screenshots/en/debian-raw.png +0 -0
  24. data/doc/images/screenshots/en/debian.png +0 -0
  25. data/doc/images/screenshots/en/green-circle-raw.png +0 -0
  26. data/doc/images/screenshots/en/green-circle.png +0 -0
  27. data/doc/images/screenshots/en/night-black-raw.png +0 -0
  28. data/doc/images/screenshots/en/night-black.png +0 -0
  29. data/doc/images/screenshots/en/rabbit-raw.png +0 -0
  30. data/doc/images/screenshots/en/rabbit.png +0 -0
  31. data/doc/images/screenshots/en/ranguba-raw.png +0 -0
  32. data/doc/images/screenshots/en/ranguba.png +0 -0
  33. data/doc/images/screenshots/en/red-frame-raw.png +0 -0
  34. data/doc/images/screenshots/en/red-frame.png +0 -0
  35. data/doc/images/screenshots/en/ruby-gnome2-raw.png +0 -0
  36. data/doc/images/screenshots/en/ruby-gnome2.png +0 -0
  37. data/doc/images/screenshots/en/rubykaigi2011-raw.png +0 -0
  38. data/doc/images/screenshots/en/rubykaigi2011.png +0 -0
  39. data/doc/images/screenshots/ja/blue-circle-raw.png +0 -0
  40. data/doc/images/screenshots/ja/blue-circle.png +0 -0
  41. data/doc/images/screenshots/ja/clear-blue-raw.png +0 -0
  42. data/doc/images/screenshots/ja/clear-blue.png +0 -0
  43. data/doc/images/screenshots/ja/cozmixng-raw.png +0 -0
  44. data/doc/images/screenshots/ja/cozmixng.png +0 -0
  45. data/doc/images/screenshots/ja/dark-gradation-raw.png +0 -0
  46. data/doc/images/screenshots/ja/dark-gradation.png +0 -0
  47. data/doc/images/screenshots/ja/day-white-raw.png +0 -0
  48. data/doc/images/screenshots/ja/day-white.png +0 -0
  49. data/doc/images/screenshots/ja/debian-raw.png +0 -0
  50. data/doc/images/screenshots/ja/debian.png +0 -0
  51. data/doc/images/screenshots/ja/green-circle-raw.png +0 -0
  52. data/doc/images/screenshots/ja/green-circle.png +0 -0
  53. data/doc/images/screenshots/ja/night-black-raw.png +0 -0
  54. data/doc/images/screenshots/ja/night-black.png +0 -0
  55. data/doc/images/screenshots/ja/rabbit-raw.png +0 -0
  56. data/doc/images/screenshots/ja/rabbit.png +0 -0
  57. data/doc/images/screenshots/ja/ranguba-raw.png +0 -0
  58. data/doc/images/screenshots/ja/ranguba.png +0 -0
  59. data/doc/images/screenshots/ja/red-frame-raw.png +0 -0
  60. data/doc/images/screenshots/ja/red-frame.png +0 -0
  61. data/doc/images/screenshots/ja/ruby-gnome2-raw.png +0 -0
  62. data/doc/images/screenshots/ja/ruby-gnome2.png +0 -0
  63. data/doc/images/screenshots/ja/rubykaigi2011-raw.png +0 -0
  64. data/doc/images/screenshots/ja/rubykaigi2011.png +0 -0
  65. data/doc/index.html.ja +2 -2
  66. data/doc/ja/how-to-make/rd.rd +30 -3
  67. data/doc/ja/index.rd +1 -1
  68. data/doc/ja/news.rd +46 -0
  69. data/doc/ja/slides.rd +1 -1
  70. data/doc/ja/usage/rabbit-theme.rd +1 -1
  71. data/doc/ja/users.rd +16 -2
  72. data/lib/rabbit/author-configuration.rb +6 -6
  73. data/lib/rabbit/command/rabbit-slide.rb +208 -161
  74. data/lib/rabbit/command/rabbit.rb +2 -2
  75. data/lib/rabbit/console.rb +1 -1
  76. data/lib/rabbit/element/text-renderer.rb +2 -2
  77. data/lib/rabbit/element/video.rb +167 -0
  78. data/lib/rabbit/image/pdf.rb +19 -10
  79. data/lib/rabbit/parser/ext/video.rb +18 -0
  80. data/lib/rabbit/parser/rd/ext/block-verbatim.rb +10 -0
  81. data/lib/rabbit/parser/rd/ext/video.rb +15 -0
  82. data/lib/rabbit/slide-configuration.rb +15 -8
  83. data/lib/rabbit/slideshare.rb +93 -13
  84. data/lib/rabbit/task/slide.rb +5 -4
  85. data/lib/rabbit/task/theme.rb +3 -1
  86. data/lib/rabbit/theme/applier.rb +1 -1
  87. data/lib/rabbit/theme/entry.rb +0 -29
  88. data/lib/rabbit/theme/title-shadow/title-shadow.rb +1 -1
  89. data/lib/rabbit/version.rb +1 -1
  90. data/lib/rabbit/video-window.rb +122 -0
  91. data/misc/github-post-receiver/config.ru +170 -0
  92. data/misc/github-post-receiver/config.yaml.sample +3 -0
  93. data/misc/github-post-receiver/tmp/restart.txt +0 -0
  94. data/po/en/rabbit.po~ +2567 -0
  95. data/po/fr/rabbit.po~ +2674 -0
  96. data/po/ja/rabbit.po~ +2695 -0
  97. data/po/rabbit.pot +1195 -1094
  98. data/rabbit.gemspec +1 -0
  99. data/test/test-author-configuration.rb +1 -0
  100. data/test/test-slide-configuration.rb +3 -0
  101. metadata +659 -640
  102. data/bin/rabbit-theme-manager +0 -133
  103. data/lib/rabbit/theme-browser.rb +0 -104
  104. data/lib/rabbit/theme-browser/default-tag.yaml +0 -89
  105. data/lib/rabbit/theme-browser/document.rb +0 -200
  106. data/lib/rabbit/theme-browser/ext/block-verbatim.rb +0 -39
  107. data/lib/rabbit/theme-browser/page.rb +0 -133
  108. data/lib/rabbit/theme-browser/rd2document-lib.rb +0 -181
  109. data/lib/rabbit/theme-browser/tag.rb +0 -67
  110. data/lib/rabbit/theme-browser/tree.rb +0 -91
@@ -613,7 +613,7 @@ module Rabbit
613
613
  end
614
614
 
615
615
  options_file = File.join(source, options.options_file)
616
- if File.exist?(options_file)
616
+ if File.file?(options_file)
617
617
  options.rest.clear
618
618
  console.read_options_file(parser, options, options_file)
619
619
  end
@@ -660,7 +660,7 @@ module Rabbit
660
660
  rest_arguments = @options.rest
661
661
  if @options.source_type == :auto
662
662
  if rest_arguments.empty?
663
- file_name = choose_source_file_by_dialog(options)
663
+ file_name = choose_source_file_by_dialog
664
664
  exit if file_name.nil?
665
665
  rest_arguments = [file_name]
666
666
  @options.source_type = Source::File
@@ -69,7 +69,7 @@ module Rabbit
69
69
 
70
70
  begin
71
71
  options_file = options.options_file
72
- if options_file and File.exist?(options_file)
72
+ if options_file and File.file?(options_file)
73
73
  read_options_file(parser, options, options_file)
74
74
  end
75
75
  options.before_hooks.each do |hook|
@@ -256,8 +256,8 @@ module Rabbit
256
256
  shadow_layout = canvas.make_layout(shadow_text)
257
257
  setup_layout(shadow_layout, @layout.width / Pango::SCALE)
258
258
  line_height = shadow_layout.pixel_size[1] / shadow_layout.line_count
259
- shadow_x = prop_value("shadow-x") || (line_height * 0.08)
260
- shadow_y = prop_value("shadow-y") || (line_height * 0.06)
259
+ shadow_x = prop_value("shadow-x") || (line_height * 0.03)
260
+ shadow_y = prop_value("shadow-y") || (line_height * 0.02)
261
261
  canvas.draw_layout(shadow_layout, x + shadow_x, y + shadow_y,
262
262
  shadow_color)
263
263
  end
@@ -0,0 +1,167 @@
1
+ require "rabbit/utils"
2
+
3
+ require "rabbit/image"
4
+ require "rabbit/element"
5
+ require "rabbit/parser/base"
6
+ require "rabbit/video-window"
7
+
8
+ module Rabbit
9
+ module Element
10
+ class Video
11
+ include Base
12
+ include BlockElement
13
+ include BlockHorizontalCentering
14
+ include TextRenderer
15
+
16
+ attr_reader :filename
17
+ attr_reader :normalized_width, :normalized_height
18
+ attr_reader :relative_width, :relative_height
19
+ attr_reader :relative_margin_top, :relative_margin_bottom
20
+ attr_reader :relative_margin_left, :relative_margin_right
21
+ attr_reader :relative_padding_top, :relative_padding_bottom
22
+ attr_reader :relative_padding_left, :relative_padding_right
23
+
24
+ def initialize(filename, prop)
25
+ @filename = filename
26
+ prop = Utils.stringify_hash_key(prop)
27
+ super()
28
+ normalized_prop = {}
29
+ prop.each do |name, value|
30
+ normalized_prop[name.gsub(/-/, '_')] = value
31
+ end
32
+ prop = normalized_prop
33
+ %w(as_large_as_possible).each do |name|
34
+ instance_variable_set("@#{name}", true_value?(prop[name]))
35
+ end
36
+ %w(width height
37
+ normalized_width normalized_height
38
+ relative_width relative_height
39
+ relative_margin_top relative_margin_bottom
40
+ relative_margin_left relative_margin_right
41
+ relative_padding_top relative_padding_bottom
42
+ relative_padding_left relative_padding_right
43
+ ).each do |name|
44
+ begin
45
+ instance_variable_set("@#{name}", prop[name] && Integer(prop[name]))
46
+ rescue ArgumentError
47
+ raise InvalidImageSizeError.new(filename, name, prop[name])
48
+ end
49
+ end
50
+
51
+ resize(@width, @height)
52
+ end
53
+
54
+ alias _compile compile
55
+ def compile_for_horizontal_centering(canvas, x, y, w, h)
56
+ _compile(canvas, x, y, w, h)
57
+ end
58
+
59
+ def compile(canvas, x, y, w, h)
60
+ super
61
+ adjust_size(canvas, @x, @y, @w, @h)
62
+ end
63
+
64
+ def width
65
+ @width.to_i + @padding_left + @padding_right
66
+ end
67
+
68
+ def height
69
+ @height.to_i + @padding_top + @padding_bottom
70
+ end
71
+
72
+ def as_large_as_possible?
73
+ @as_large_as_possible
74
+ end
75
+
76
+ def draw_element(canvas, x, y, w, h, simulation)
77
+ unless simulation
78
+ if canvas.display?
79
+ @video_window ||= VideoWindow.new(self)
80
+ @video_window.show(canvas.window)
81
+ else
82
+ draw_layout(canvas, x, y)
83
+ end
84
+ end
85
+ [x, y + height, w, h - height]
86
+ end
87
+
88
+ def text
89
+ "video : #{File.basename(@filename)}"
90
+ end
91
+
92
+ def to_rd
93
+ text
94
+ end
95
+
96
+ private
97
+ def adjust_margin(w, h)
98
+ @margin_top =
99
+ make_relative_size(@relative_margin_top, h) || @margin_top
100
+ @margin_bottom =
101
+ make_relative_size(@relative_margin_bottom, h) || @margin_bottom
102
+ @margin_left =
103
+ make_relative_size(@relative_margin_left, w) || @margin_left
104
+ @margin_right =
105
+ make_relative_size(@relative_margin_right, w) || @margin_right
106
+ end
107
+
108
+ def adjust_padding(w, h)
109
+ @padding_top =
110
+ make_relative_size(@relative_padding_top, h) || @padding_top
111
+ @padding_bottom =
112
+ make_relative_size(@relative_padding_bottom, h) || @padding_bottom
113
+ @padding_left =
114
+ make_relative_size(@relative_padding_left, w) || @padding_left
115
+ @padding_right =
116
+ make_relative_size(@relative_padding_right, w) || @padding_right
117
+ end
118
+
119
+ def adjust_size(canvas, x, y, w, h)
120
+ base_w = w
121
+ base_h = h
122
+ adjust_margin(base_w, base_h)
123
+ adjust_padding(base_w, base_h)
124
+ base_h = base_h - @padding_top - @padding_bottom
125
+ if @as_large_as_possible
126
+ iw = base_w
127
+ ih = base_h
128
+ else
129
+ nw = make_normalized_size(@normalized_width)
130
+ nh = make_normalized_size(@normalized_height)
131
+ rw = make_relative_size(@relative_width, base_w)
132
+ rh = make_relative_size(@relative_height, base_h)
133
+ iw = nw || rw || base_w
134
+ ih = nh || rh || base_h
135
+ end
136
+ resize(iw, ih)
137
+ end
138
+
139
+ def resize(w, h)
140
+ if w.nil? and h.nil?
141
+ return
142
+ else
143
+ w ||= width
144
+ h ||= height
145
+ end
146
+ w = w.ceil if w
147
+ h = h.ceil if h
148
+ if w and w > 0 and h and h > 0 and [w, h] != [width, height]
149
+ @width = w
150
+ @height = h
151
+ end
152
+ end
153
+
154
+ def make_normalized_size(size)
155
+ size && screen_size(size)
156
+ end
157
+
158
+ def make_relative_size(size, parent_size)
159
+ size && parent_size && ((size / 100.0) * parent_size).ceil
160
+ end
161
+
162
+ def true_value?(value)
163
+ value == true or value == "true"
164
+ end
165
+ end
166
+ end
167
+ end
@@ -7,22 +7,29 @@ require "rabbit/image/base"
7
7
  module Rabbit
8
8
  module ImageManipulable
9
9
  class PDF < Base
10
+ include GetText
10
11
 
11
12
  unshift_loader(self)
12
13
 
13
14
  class << self
14
15
  def match?(filename)
15
- File.open(filename) do |f|
16
- line = f.gets
17
- line and /\A%PDF-1\.\d\z/ =~ line.chomp
16
+ return true if File.extname(filename) == ".pdf"
17
+
18
+ File.open(filename) do |file|
19
+ line = file.gets
20
+ return false if line.nil?
21
+
22
+ begin
23
+ /\A%PDF-1\.\d\z/ =~ line.chomp
24
+ rescue ArgumentError
25
+ false
26
+ end
18
27
  end
19
- rescue ArgumentError
20
- false
21
28
  end
22
29
  end
23
30
 
24
31
  def draw(canvas, x, y, params={})
25
- if @doc and canvas.poppler_available?
32
+ if @document and canvas.poppler_available?
26
33
  default_params = {
27
34
  :width => width,
28
35
  :height => height,
@@ -39,21 +46,23 @@ module Rabbit
39
46
 
40
47
  private
41
48
  def page
42
- index = self["page"] || 0
49
+ index = self["page"] || 1
43
50
  begin
44
51
  index = Integer(index)
45
52
  rescue ArgumentError
53
+ message = _("invalid PDF page number: <%s>") % index.inspect
54
+ raise ImageLoadError.new("#{@filename}: #{message}")
46
55
  end
47
- _page = @doc[index]
56
+ _page = @document[index - 1]
48
57
  if _page.nil?
49
- message = _("%s page isn't exist in PDF") % index.inspect
58
+ message = _("%s page doesn't exist in PDF") % index
50
59
  raise ImageLoadError.new("#{@filename}: #{message}")
51
60
  end
52
61
  _page
53
62
  end
54
63
 
55
64
  def update_size
56
- @doc = Poppler::Document.new(uri)
65
+ @document = Poppler::Document.new(uri)
57
66
  @width, @height = page.size
58
67
  end
59
68
 
@@ -0,0 +1,18 @@
1
+ require 'rabbit/element'
2
+
3
+ module Rabbit
4
+ module Parser
5
+ module Ext
6
+ module Video
7
+ def make_video(canvas, path, prop)
8
+ begin
9
+ Element::Video.new(path, prop)
10
+ rescue Error
11
+ canvas.logger.warn($!.message)
12
+ nil
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -8,6 +8,7 @@ rescue LoadError
8
8
  end
9
9
  require 'rabbit/parser/rd/ext/base'
10
10
  require 'rabbit/parser/rd/ext/image'
11
+ require 'rabbit/parser/rd/ext/video'
11
12
  require 'rabbit/parser/ext/enscript'
12
13
  require 'rabbit/parser/ext/tex'
13
14
  require 'rabbit/parser/ext/aafigure'
@@ -21,6 +22,7 @@ module Rabbit
21
22
  module Ext
22
23
  class BlockVerbatim < Base
23
24
  include Image
25
+ include Video
24
26
  include GetText
25
27
 
26
28
  def default_ext_block_verbatim(label, source, content, visitor)
@@ -60,6 +62,14 @@ module Rabbit
60
62
  end
61
63
  end
62
64
 
65
+ def ext_block_verb_video(label, source, content, visitor)
66
+ return nil unless /^video$/i =~ label
67
+ src, prop = parse_source(source)
68
+ return nil if prop['src'].nil?
69
+
70
+ make_video(visitor, prop['src'], prop)
71
+ end
72
+
63
73
  def ext_block_verb_enscript(label, source, content, visitor)
64
74
  return nil unless /^enscript (\w+)$/i =~ label
65
75
  lang = $1.downcase.untaint
@@ -0,0 +1,15 @@
1
+ require 'rabbit/element'
2
+ require 'rabbit/parser/ext/video'
3
+
4
+ module Rabbit
5
+ module Parser
6
+ class RD
7
+ module Ext
8
+ module Video
9
+ include Parser::Ext::Video
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+
@@ -32,7 +32,8 @@ module Rabbit
32
32
 
33
33
  attr_accessor :logger
34
34
  attr_accessor :id, :base_name, :tags, :presentation_date
35
- attr_accessor :licenses, :slideshare_id, :speaker_deck_id
35
+ attr_accessor :licenses
36
+ attr_accessor :slideshare_id, :speaker_deck_id, :ustream_id, :vimeo_id
36
37
  attr_writer :version
37
38
  attr_accessor :author
38
39
  def initialize(logger=nil)
@@ -69,21 +70,25 @@ module Rabbit
69
70
  @licenses = []
70
71
  @slideshare_id = nil
71
72
  @speaker_deck_id = nil
73
+ @ustream_id = nil
74
+ @vimeo_id = nil
72
75
  @author = nil
73
76
  end
74
77
 
75
78
  def merge!(conf)
76
- @id ||= conf["id"]
77
- @base_name ||= conf["base_name"]
78
- @presentation_date ||= conf["presentation_date"]
79
- @version ||= conf["version"]
80
- @slideshare_id ||= conf["slideshare_id"]
81
- @speaker_deck_id ||= conf["speaker_deck_id"]
79
+ @id = conf["id"] || @id
80
+ @base_name = conf["base_name"] || @base_name
81
+ @presentation_date = conf["presentation_date"] || @presentation_date
82
+ @version = conf["version"] || @version
83
+ @slideshare_id = conf["slideshare_id"] || @slideshare_id
84
+ @speaker_deck_id = conf["speaker_deck_id"] || @speaker_deck_id
85
+ @ustream_id = conf["ustream_id"] || @ustream_id
86
+ @vimeo_id = conf["vimeo_id"] || @vimeo_id
82
87
 
83
88
  @tags |= (conf["tags"] || [])
84
89
  @licenses |= (conf["licenses"] || [])
85
90
 
86
- @author = AuthorConfiguration.new(@logger)
91
+ @author ||= AuthorConfiguration.new(@logger)
87
92
  @author.merge!(conf["author"] || {})
88
93
  end
89
94
 
@@ -97,6 +102,8 @@ module Rabbit
97
102
  "licenses" => @licenses,
98
103
  "slideshare_id" => @slideshare_id,
99
104
  "speaker_deck_id" => @speaker_deck_id,
105
+ "ustream_id" => @ustream_id,
106
+ "vimeo_id" => @vimeo_id,
100
107
  }
101
108
  config["author"] = @author.to_hash if @author
102
109
  config
@@ -26,6 +26,9 @@ require "rabbit/command/rabbit"
26
26
  module Rabbit
27
27
  module Task
28
28
  class SlideShare
29
+ class Error < StandardError
30
+ end
31
+
29
32
  include GetText
30
33
 
31
34
  BASE_URL = "https://www.slideshare.net"
@@ -33,11 +36,12 @@ module Rabbit
33
36
  API_KEY = "NB1B0IzS"
34
37
  SHARED_SECRET = "iuTFlPzU"
35
38
 
36
- attr_accessor :user, :pdf_path, :title, :description, :tags
39
+ attr_accessor :user, :pdf_path, :id, :title, :description, :tags
37
40
  def initialize(logger)
38
41
  @logger = logger
39
42
  @user = nil
40
43
  @pdf_path = nil
44
+ @id = nil
41
45
  @title = nil
42
46
  @description = nil
43
47
  @tags = []
@@ -50,24 +54,89 @@ module Rabbit
50
54
  end
51
55
 
52
56
  def upload
57
+ slideshow_id = nil
58
+ begin
59
+ slideshow_id = upload_slide
60
+ rescue Error
61
+ @logger.error(_("Feailed to upload: %s") % $!.message)
62
+ return nil
63
+ end
64
+
65
+ begin
66
+ edit_title(slideshow_id)
67
+ rescue Error
68
+ @logger.error(_("Feailed to edit title: %s") % $!.message)
69
+ return nil
70
+ end
71
+
72
+ url = nil
73
+ begin
74
+ url = slide_url(slideshow_id)
75
+ rescue Error
76
+ @logger.error(_("Feailed to get slide URL: %s") % $!.message)
77
+ return nil
78
+ end
79
+ url
80
+ end
81
+
82
+ private
83
+ def upload_slide
53
84
  payload = {
54
85
  :username => @user,
55
86
  :password => password,
56
- :slideshow_title => @title,
87
+ :slideshow_title => upload_title,
57
88
  :slideshow_srcfile => Faraday::UploadIO.new(@pdf_path,
58
89
  "application/pdf"),
59
90
  :slideshow_description => @description,
60
91
  :tags => @tags.join(","),
61
92
  }
93
+ response = post("upload_slideshow", payload)
94
+ parse_upload_slideshow_response(response)
95
+ end
96
+
97
+ def edit_title(slideshow_id)
98
+ payload = {
99
+ :username => @user,
100
+ :password => password,
101
+ :slideshow_id => slideshow_id,
102
+ :slideshow_title => @title,
103
+ }
104
+ response = get("edit_slideshow", payload)
105
+ parse_edit_slideshow_response(response)
106
+ end
107
+
108
+ def slide_url(slideshow_id)
109
+ payload = {
110
+ :slideshow_id => slideshow_id,
111
+ }
112
+ response = get("get_slideshow", payload)
113
+ parse_get_slideshow_response(response)
114
+ end
115
+
116
+ def prepare_payload(payload)
62
117
  payload = common_payload.merge(payload)
63
118
  payload.keys.each do |key|
64
119
  payload.delete(key) if payload[key].nil?
65
120
  end
66
- parse_response(@connection.post("#{API_PATH_PREFIX}/upload_slideshow",
67
- payload))
121
+ payload
122
+ end
123
+
124
+ def get(command, payload)
125
+ @connection.get(api_url(command), prepare_payload(payload))
126
+ end
127
+
128
+ def post(command, payload)
129
+ @connection.post(api_url(command), prepare_payload(payload))
130
+ end
131
+
132
+ def api_url(command)
133
+ "#{API_PATH_PREFIX}/#{command}"
134
+ end
135
+
136
+ def upload_title
137
+ @id.gsub(/-/, " ")
68
138
  end
69
139
 
70
- private
71
140
  def password
72
141
  @password ||= read_password(_("Enter password on SlideShare"))
73
142
  end
@@ -96,20 +165,31 @@ module Rabbit
96
165
  @logger.debug(http_response.body)
97
166
 
98
167
  unless http_response.success?
99
- detail = "#{http_response.status}\n#{http_response.body}"
100
- @logger.error(_("Failed to upload: %s") % detail)
101
- return nil
168
+ raise Error, "#{http_response.status}\n#{http_response.body}"
102
169
  end
103
170
 
104
- puts http_response.body
105
171
  response = Nokogiri::XML(http_response.body)
106
172
  if response.root.name == "SlideShareServiceError"
107
173
  message = response.root.elements[0]
108
- @logger.error("Failed to upload: %s" % message.text)
109
- nil
110
- else
111
- response.xpath("/SlideShowUploaded/SlideShowID").text.to_i
174
+ raise Error, message
112
175
  end
176
+
177
+ response
178
+ end
179
+
180
+ def parse_upload_slideshow_response(http_response)
181
+ response = parse_response(http_response)
182
+ response.xpath("/SlideShowUploaded/SlideShowID").text.to_i
183
+ end
184
+
185
+ def parse_edit_slideshow_response(http_response)
186
+ response = parse_response(http_response)
187
+ response.xpath("/SlideShowEdited/SlideShowID").text.to_i
188
+ end
189
+
190
+ def parse_get_slideshow_response(http_response)
191
+ response = parse_response(http_response)
192
+ response.xpath("/Slideshow/URL").text
113
193
  end
114
194
  end
115
195
  end