Class: Wordy::Job
- Inherits:
-
Object
- Object
- Wordy::Job
- Defined in:
- lib/wordy/job.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
- .all ⇒ Object
-
.create(language, content, title = nil, callback_url = nil, intrusive_editing = false, brief = nil) ⇒ Object
Parameters ———- language_id intrusive_editing (known in the front-end as content rewrite) true or false brief fileToUpload single file to be edited (not supported by this gem) content raw text to be edited json flat dictionary of content to be edited ‘Title”:“My Content”’.
- .find(id) ⇒ Object
- .find_edited_document(id) ⇒ Object
Instance Method Summary collapse
- #confirm! ⇒ Object
- #conversation ⇒ Object
- #edited_document ⇒ Object
- #info ⇒ Object
-
#initialize(hash) ⇒ Job
constructor
A new instance of Job.
- #metaclass ⇒ Object
- #pay! ⇒ Object
- #reject! ⇒ Object
- #set_attributes(hash) ⇒ Object
- #update_conversation(message) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Job
Returns a new instance of Job.
5 6 7 8 |
# File 'lib/wordy/job.rb', line 5 def initialize(hash) @attributes = {} set_attributes(hash) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/wordy/job.rb', line 3 def attributes @attributes end |
Class Method Details
.all ⇒ Object
60 61 62 63 64 65 |
# File 'lib/wordy/job.rb', line 60 def all response = Cli.http_get(Wordy.wordy_url+"job/", {}) response.map do |job_id| new({'id' => job_id}) end end |
.create(language, content, title = nil, callback_url = nil, intrusive_editing = false, brief = nil) ⇒ Object
Parameters
language_id intrusive_editing (known in the front-end as content rewrite) true or false brief fileToUpload single file to be edited (not supported by this gem) content raw text to be edited json flat dictionary of content to be edited ‘Title”:“My Content”’
Can only use one of those parameters: fileToUpload, content, json
Response
id ID of the newly created job url URL fragment of the newly created job
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/wordy/job.rb', line 48 def create(language, content, title=nil, callback_url=nil, intrusive_editing=false, brief=nil) parameters = {:language_id => language, :intrusive_editing => intrusive_editing, :brief => brief, :callback_url => callback_url} if !title.nil? && !title.empty? parameters[:json] = ActiveSupport::JSON.encode({title => content}) else parameters[:content] = content end parameters = parameters.delete_if{|key, value| value.nil? } response = Cli.http_post(Wordy.wordy_url+'job/create/', parameters) return new(response) end |
.find(id) ⇒ Object
67 68 69 70 71 |
# File 'lib/wordy/job.rb', line 67 def find(id) job = new('id' => id) job.info job end |
.find_edited_document(id) ⇒ Object
73 74 75 76 77 |
# File 'lib/wordy/job.rb', line 73 def find_edited_document(id) job = new('id' => id) job.edited_document job end |
Instance Method Details
#confirm! ⇒ Object
103 104 105 |
# File 'lib/wordy/job.rb', line 103 def confirm! Cli.http_post(Wordy.wordy_url+"job/#{self.id}/confirm/", {}) end |
#conversation ⇒ Object
91 92 93 |
# File 'lib/wordy/job.rb', line 91 def conversation Cli.http_get(Wordy.wordy_url+"job/#{self.id}/conversation/", {}) end |
#edited_document ⇒ Object
85 86 87 88 89 |
# File 'lib/wordy/job.rb', line 85 def edited_document response = Cli.http_get(Wordy.wordy_url+"job/#{self.id}/target/", {}) edited_content = response.values[0] set_attributes({:edited_content => edited_content}) end |
#info ⇒ Object
80 81 82 83 |
# File 'lib/wordy/job.rb', line 80 def info response = Cli.http_get(Wordy.wordy_url+"job/#{self.id}/", {}) set_attributes(response) end |
#metaclass ⇒ Object
23 24 25 26 27 |
# File 'lib/wordy/job.rb', line 23 def class << self self end end |
#pay! ⇒ Object
99 100 101 |
# File 'lib/wordy/job.rb', line 99 def pay! Cli.http_post(Wordy.wordy_url+"job/#{self.id}/pay/", {}) end |
#reject! ⇒ Object
107 108 109 |
# File 'lib/wordy/job.rb', line 107 def reject! Cli.http_post(Wordy.wordy_url+"job/#{self.id}/reject/", {}) end |
#set_attributes(hash) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/wordy/job.rb', line 10 def set_attributes(hash) @attributes.update hash hash.each do |key, value| .send :attr_accessor, key if %w(delivery_date created).include? key value = DateTime.strptime(value.to_s,'%s') elsif key == "cost" value = value.to_s.match(/[^0-9]?([0-9]+\.{0,1}[0-9]+)/)[1].to_f end instance_variable_set("@#{key}", value) end end |