Added: model wrapper

This commit is contained in:
suer
2014-02-18 23:45:13 +09:00
parent f544dac4a7
commit 60b8e213e3
4 changed files with 40 additions and 18 deletions

11
Gemfile.lock Normal file
View File

@@ -0,0 +1,11 @@
GEM
specs:
faraday (0.8.8)
multipart-post (~> 1.2.0)
multipart-post (1.2.0)
PLATFORMS
ruby
DEPENDENCIES
faraday

View File

@@ -1,4 +1,5 @@
require 'redmine_webhook/projects_helper_patch'
require 'redmine_webhook/issue_wrapper'
require 'redmine_webhook/webhook_listener'
module RedmineWebhook

View File

@@ -0,0 +1,27 @@
class RedmineWebhook::IssueWrapper
def initialize(issue)
@issue = issue
end
def to_json
{
:action => "create",
:issue => {
:id => @issue.id,
:subject => @issue.subject,
:description => @issue.description,
:created_on => @issue.created_on,
:updated_on => @issue.updated_on,
:closed_on => @issue.closed_on,
:root_id => @issue.root_id,
:parent_id => @issue.parent_id,
:done_ratio => @issue.done_ratio,
:start_date => @issue.start_date,
:due_date => @issue.due_date,
:estimated_hours => @issue.estimated_hours,
:is_private => @issue.is_private,
:lock_version => @issue.lock_version
}
}.to_json
end
end

View File

@@ -4,7 +4,7 @@ class RedmineWebhook::WebhookListener < Redmine::Hook::Listener
project = issue.project
webhook = Webhook.where(:project_id => project.project.id).first
return unless webhook
post(webhook, issue_create_payload(issue))
post(webhook, RedmineWebhook::IssueWrapper.new(issue).to_json)
end
def controller_issues_edit_after_save(context = {})
@@ -17,23 +17,6 @@ class RedmineWebhook::WebhookListener < Redmine::Hook::Listener
end
private
def issue_create_payload(issue)
{:payload => issue}.to_json(issues_to_json_option)
end
def issues_to_json_option
{
:include => [
{:project => {:only => [:id, :identifier, :name, :description, :homepage, :created_on, :updated_at]}},
{:status => {:only => [:id, :name]}},
{:tracker => {:only => [:id, :name]}},
{:priority => {:only => [:id, :name]}},
{:author => {:only => [:login, :mail, :firstname, :lastname, :identity_url]}},
{:assigned_to => {:only => [:login, :mail, :firstname, :lastname, :identity_url]}}
]
}
end
def journal_create_payload(journal)
{:payload => journal}.to_json(journal_to_json_option)
end