simplificator-rwebthumb 0.3.1 → 0.3.2

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.
@@ -11,6 +11,7 @@ module Simplificator
11
11
  VALID_SIZES = [:small, :medium, :medium2, :large, :full, :excerpt, :effect, :custom, :zip]
12
12
 
13
13
  attr_reader :api_key
14
+ attr_reader :api_endpoint
14
15
  # Constructor
15
16
  # api_key: the Webthumb api key, not nil and not blank
16
17
  #
@@ -46,7 +47,7 @@ module Simplificator
46
47
  raise WebthumbException.new("Unsupported content type #{response.content_type}")
47
48
  end
48
49
  else
49
- raise CommunicationException('Response code was not HTTP OK')
50
+ raise CommunicationException.new('Response code was not HTTP OK')
50
51
  end
51
52
  end
52
53
 
@@ -56,6 +57,7 @@ module Simplificator
56
57
  root = REXML::Element.new('webthumb')
57
58
  api = root.add_element('apikey')
58
59
  api.text = @api_key
60
+ root.add_element('version').text='3'
59
61
  root
60
62
  end
61
63
 
@@ -10,21 +10,21 @@ module Simplificator
10
10
  STATUS_PICKUP = 200
11
11
 
12
12
  # Factory method to build a Job object from a REXML xml element
13
- def self.from_thumbnail_xml(api_key, xml)
13
+ def self.from_thumbnail_xml(api_key, api_endpoint, xml)
14
14
  job_element = REXML::XPath.first(xml, '/webthumb/jobs/job')
15
15
  return nil if job_element.nil?
16
16
 
17
17
  submission_datetime = self.parse_webthumb_datetime(job_element.attributes['time'])
18
- Job.new(api_key, job_element.text, job_element.attributes['url'], submission_datetime, job_element.attributes['estimate'].to_i, job_element.attributes['cost'].to_i)
18
+ Job.new(api_key, api_endpoint, job_element.text, job_element.attributes['url'], submission_datetime, job_element.attributes['estimate'].to_i, job_element.attributes['cost'].to_i)
19
19
  end
20
20
  # Factory method to create a Job object from a status XML.
21
21
  # this does not set all attributes of the Job (url, duration_estimate, cost) since the API of webthumb does not
22
22
  # return the same information on job creation and status requests.
23
- def self.from_status_xml(api_key, xml)
23
+ def self.from_status_xml(api_key, api_endpoint, xml)
24
24
  status_element = REXML::XPath.first(xml, '/webthumb/jobStatus/status')
25
25
  submission_datetime = self.parse_webthumb_datetime(status_element.attributes['submissionTime'])
26
- job = Job.new(api_key, status_element.attributes['id'], nil, submission_datetime, 5, nil,
27
- status_element.text == 'Complete' ? STATUS_PICKUP : STATUS_PROCESSING)
26
+ job = Job.new(api_key, api_endpoint, status_element.attributes['id'], nil, submission_datetime, 5, nil,
27
+ status_element.text.downcase == 'complete' ? STATUS_PICKUP : STATUS_PROCESSING)
28
28
  end
29
29
  # Constructor.
30
30
  # *api_key: webthumb API key. Required by all the operations which query the server
@@ -34,8 +34,8 @@ module Simplificator
34
34
  # *duration_estimate: integer value indicating estimated job duration in seconds
35
35
  # *cost: integer value indicating how many credit this request costet. Optional
36
36
  # *status: one of the STATUS_XXX constants defined in Base. Defaults to STATUS_PROCESSING
37
- def initialize(api_key, job_id, url, submission_datetime, duration_estimate, cost, status = STATUS_PROCESSING)
38
- super(api_key)
37
+ def initialize(api_key, api_endpoint, job_id, url, submission_datetime, duration_estimate, cost, status = STATUS_PROCESSING)
38
+ super(api_key, api_endpoint)
39
39
  @job_id = job_id
40
40
  @url = url
41
41
  @submission_datetime = submission_datetime
@@ -50,15 +50,16 @@ module Simplificator
50
50
  # A call to this method updates the @status attribute.
51
51
  def check_status
52
52
  response = do_request(build_status_xml())
53
- @status = REXML::XPath.first(response, '/webthumb/jobStatus/status').text == 'Complete' ? STATUS_PICKUP : STATUS_PROCESSING
53
+ status_elem = REXML::XPath.first(response,'/webthumb/jobStatus/status')
54
+ @status = status_elem.text.downcase == 'complete' ? STATUS_PICKUP : STATUS_PROCESSING
54
55
 
55
56
  if pickup?
56
- @completion_time = response.attributes['completionTime']
57
57
 
58
- if REXML::XPath.first(response,'/webthumb/jobStatus/status')
59
- @pickup_url = REXML::XPath.first(response,'/webthumb/jobStatus/status').attributes['pickup']
60
- @browser_width = (REXML::XPath.first(response,'/webthumb/jobStatus/status').attributes['browserWidth'] || "0").to_i
61
- @browser_height = (REXML::XPath.first(response,'/webthumb/jobStatus/status').attributes['browserHeight'] || "0").to_i
58
+ if status_elem
59
+ @completion_time = status_elem.attributes['completionTime']
60
+ @pickup_url = status_elem.attributes['pickup']
61
+ @browser_width = (status_elem.attributes['browserWidth'] || "0").to_i
62
+ @browser_height = (status_elem.attributes['browserHeight'] || "0").to_i
62
63
  end
63
64
  end
64
65
  @status
@@ -139,7 +140,8 @@ module Simplificator
139
140
  end
140
141
 
141
142
  def to_s
142
- "Job: #{@job_id} / Status: #{@status} / Submission Time #{@submission_time} / Duration Estimate #{@duration_estimate}"
143
+ extra = @pickup_url ? " / Completion Time: #{@completion_time} / Pickup Url: #{@pickup_url}" : ''
144
+ "Job: #{@job_id} / Status: #{@status} / Submission Time #{@submission_datetime} / Duration Estimate #{@duration_estimate}#{extra}"
143
145
  end
144
146
  end
145
147
  end
@@ -31,7 +31,7 @@ module Simplificator
31
31
  # defined in Base.rb for valid values
32
32
  #
33
33
  def thumbnail(options = {})
34
- Job.from_thumbnail_xml(@api_key, do_request(build_thumbnail_xml(options)))
34
+ Job.from_thumbnail_xml(@api_key, @api_endpoint, do_request(build_thumbnail_xml(options)))
35
35
  end
36
36
 
37
37
  # Request the job status from server.
@@ -41,7 +41,7 @@ module Simplificator
41
41
  # the requested URL, the duration estimation and the cost values when checking the status. I hope this will change someday.
42
42
  def job_status(job_id)
43
43
  raise WebthumbException.new('Job id is required') if job_id == nil || job_id == ''
44
- Job.from_status_xml(@api_key, do_request(build_job_status_xml(job_id)))
44
+ Job.from_status_xml(@api_key, @api_endpoint, do_request(build_job_status_xml(job_id)))
45
45
  end
46
46
 
47
47
  # Check your credit status on the webthumbs server
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplificator-rwebthumb
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.3.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 2
9
+ version: 0.3.2
6
10
  platform: ruby
7
11
  authors:
8
12
  - Simplificator GmbH
@@ -10,7 +14,8 @@ autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
16
 
13
- date: 2008-09-03 00:00:00 Z
17
+ date: 2008-09-03 00:00:00 +02:00
18
+ default_executable:
14
19
  dependencies: []
15
20
 
16
21
  description: "rwebthumb provides a ruby interface for the webthumb.bluga.net. "
@@ -33,6 +38,7 @@ files:
33
38
  - lib/rwebthumb/easythumb.rb
34
39
  - README
35
40
  - init.rb
41
+ has_rdoc: true
36
42
  homepage: http://simplificator.com/
37
43
  licenses: []
38
44
 
@@ -42,21 +48,23 @@ rdoc_options: []
42
48
  require_paths:
43
49
  - lib
44
50
  required_ruby_version: !ruby/object:Gem::Requirement
45
- none: false
46
51
  requirements:
47
52
  - - ">="
48
53
  - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
49
56
  version: "0"
50
57
  required_rubygems_version: !ruby/object:Gem::Requirement
51
- none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
55
63
  version: "0"
56
64
  requirements: []
57
65
 
58
66
  rubyforge_project:
59
- rubygems_version: 1.8.8
67
+ rubygems_version: 1.3.6
60
68
  signing_key:
61
69
  specification_version: 3
62
70
  summary: rwebthumb provides a ruby interface for the webthumb.bluga.net