simplificator-rwebthumb 0.2.6 → 0.2.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.
data/README CHANGED
@@ -4,13 +4,9 @@
4
4
  A Ruby wrapper for the webthumb API from http://webthumb.bluga.net and a generator
5
5
  for the easythumb API
6
6
 
7
- = dependencies
8
- * tzinfo:http://tzinfo.rubyforge.org (install: sudo gem install tzinfo)
9
-
10
7
  = Installation
11
8
  sudo gem update --system (in case you are not yet on version 1.2.0 or higher)
12
9
  sudo gem sources -a http://gems.github.com (only once)
13
- sudo gem install tzinfo
14
10
  sudo gem install simplificator-rwebthumb
15
11
 
16
12
 
@@ -30,9 +26,9 @@ job = wt.thumbnail(:url => 'http://simplificator.com')
30
26
  # if thumb is not ready yet
31
27
  job.fetch(:large)
32
28
 
33
- # you can check the status of a job
29
+ # you can check the status of a job
34
30
  job.check_status()
35
-
31
+
36
32
  # or fetch the thumbnail when it is complete
37
33
  job.fetch_when_complete(:large)
38
34
 
data/lib/rwebthumb.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'tzinfo'
1
+ require 'time'
2
2
  require 'rwebthumb/base'
3
3
  require 'rwebthumb/job'
4
4
  require 'rwebthumb/webthumb'
5
- require 'rwebthumb/easythumb'
5
+ require 'rwebthumb/easythumb'
@@ -1,6 +1,6 @@
1
1
  module Simplificator
2
2
  module Webthumb
3
- #
3
+ #
4
4
  #
5
5
  #
6
6
  #
@@ -9,14 +9,11 @@ module Simplificator
9
9
  VALID_OUTPUT_TYPES = [:jpg, :png]
10
10
  # Valid values for size element in fetch requests
11
11
  VALID_SIZES = [:small, :medium, :medium2, :large, :full, :excerpt, :effect, :custom, :zip]
12
-
13
- # Timezone to convert from MST (Webthumb) to UTC
14
- MST_TIMEZONE = TZInfo::Timezone.get('MST')
15
-
12
+
16
13
  attr_reader :api_key
17
14
  # Constructor
18
15
  # api_key: the Webthumb api key, not nil and not blank
19
- #
16
+ #
20
17
  def initialize(api_key, api_endpoint = 'http://webthumb.bluga.net/api.php')
21
18
  raise WebthumbException.new('Need an not nil and not blank api_key') if api_key == nil || api_key == ''
22
19
  @api_key = api_key
@@ -24,13 +21,13 @@ module Simplificator
24
21
  @api_uri = URI.parse(@api_endpoint)
25
22
  end
26
23
 
27
- # Parse the datetime string and returns a DateTime object in UTC time
24
+ # Parse the datetime string and returns a DateTime object in UTC time
28
25
  # Webthumb returns the time in MST (Mountain Standard Time) which is some 7 hours
29
26
  # behind UTC
30
27
  def self.parse_webthumb_datetime(s)
31
- MST_TIMEZONE.local_to_utc(DateTime.strptime(s, '%Y-%m-%d %H:%M:%S'))
28
+ Time.parse("#{s} MST").getutc
32
29
  end
33
-
30
+
34
31
  def do_request(xml)
35
32
  request = Net::HTTP::Post.new(@api_uri.path)
36
33
  request.body = xml.to_s
@@ -45,11 +42,11 @@ module Simplificator
45
42
  else
46
43
  raise WebthumbException.new("usupported content type #{response.content_type}. Body was: \n#{response.body}")
47
44
  end
48
- else
45
+ else
49
46
  raise CommunicationException('Response code was not HTTP OK')
50
47
  end
51
48
  end
52
-
49
+
53
50
  # builds the root node for webthumb requtes
54
51
  def build_root_node()
55
52
  root = REXML::Element.new('webthumb')
@@ -57,12 +54,12 @@ module Simplificator
57
54
  api.text = @api_key
58
55
  root
59
56
  end
60
-
57
+
61
58
  protected
62
59
  #
63
60
  # add a XML element if value is present.
64
61
  # can be used to create XML for webthumb requests from ruby options hash.
65
- #
62
+ #
66
63
  # root: the root XML element where element is added to
67
64
  # options: the hash where value is taken from
68
65
  # key: the key to lookup the value in options
@@ -78,4 +75,4 @@ module Simplificator
78
75
  class CommunicationException < RuntimeError
79
76
  end
80
77
  end
81
- end
78
+ end
data/test/base_test.rb CHANGED
@@ -4,15 +4,15 @@ class BaseTest < Test::Unit::TestCase
4
4
  assert_raises(WebthumbException) { Base.new('') }
5
5
  assert_raises(WebthumbException) { Base.new(nil) }
6
6
  end
7
-
7
+
8
8
  def test_parse_webthumb_date
9
9
  [['2000-1-1 14:00:00', '2000-1-1 07:00:00'], ['2000-1-1 07:00:00', '2000-1-1 00:00:00'], ['2000-8-1 07:44:2', '2000-8-1 00:44:02']].each do |item|
10
- utc = DateTime.strptime(item[0], '%Y-%m-%d %H:%M:%S')
10
+ utc = Time.parse("#{item[0]} UTC")
11
11
  mst = Base.parse_webthumb_datetime(item[1])
12
12
  assert_equal(utc, mst)
13
13
  end
14
14
  end
15
-
15
+
16
16
  def test_build_root_node()
17
17
  root = Base.new('1234').build_root_node()
18
18
  assert_not_nil(root)
@@ -20,4 +20,4 @@ class BaseTest < Test::Unit::TestCase
20
20
  assert_not_nil(REXML::XPath.first(root, '/apikey'))
21
21
  assert_equal('1234', REXML::XPath.first(root, '/apikey').text)
22
22
  end
23
- end
23
+ end
data/test/job_test.rb CHANGED
@@ -12,24 +12,24 @@ class JobTest < Test::Unit::TestCase
12
12
  @job = Job.from_thumbnail_xml('1234', job_xml)
13
13
  end
14
14
  def test_from_thumbnail_xml
15
-
15
+
16
16
  assert_equal('1234', @job.api_key)
17
17
  assert_equal(20, @job.duration_estimate)
18
- assert_equal(DateTime.strptime('2008-02-27 19:49:48', '%Y-%m-%d %H:%M:%S'), @job.submission_datetime)
18
+ assert_equal(Time.parse('2008-02-27 19:49:48 UTC'), @job.submission_datetime)
19
19
  assert_equal('http://blog.joshuaeichorn.com', @job.url)
20
20
  assert_equal(1, @job.cost)
21
21
  assert_equal('wt47c5f71c37c3a', @job.job_id)
22
22
  end
23
-
24
-
23
+
24
+
25
25
  def test_build_fetch()
26
26
  xml = @job.send(:build_fetch_xml)
27
27
  assert_equal('small', REXML::XPath.first(xml, 'fetch/size').text)
28
28
  assert_equal('wt47c5f71c37c3a', REXML::XPath.first(xml, 'fetch/job').text)
29
29
  end
30
-
30
+
31
31
  def test_build_status_xml()
32
32
  xml = @job.send(:build_status_xml)
33
33
  assert_equal('wt47c5f71c37c3a', REXML::XPath.first(xml, 'status/job').text)
34
34
  end
35
- end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplificator-rwebthumb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simplificator GmbH