{"action":"created","comment":{"url":"https://api.github.com/repos/devlab-oy/pupenext/pulls/comments/61560388","id":61560388,"diff_hunk":"@@ -2,11 +2,59 @@ class HuutokauppaJob < ActiveJob::Base\n   queue_as :huutokauppa\n \n   def perform(id:)\n-    incoming_mail = IncomingMail.find(id)\n+    @incoming_mail = IncomingMail.find(id)\n \n-    incoming_mail.update(\n-      processed_at: Time.now,\n-      status: :ok\n-    )\n+    Current.company = @incoming_mail.company\n+    Current.user    = Current.company.users.find_by!(kuka: 'admin')\n+\n+    @huutokauppa_mail = HuutokauppaMail.new(@incoming_mail.raw_source)\n+\n+    case @huutokauppa_mail.type\n+    when :offer_accepted, :offer_automatically_accepted\n+      update_order_customer_and_product_info\n+    when :purchase_price_paid\n+      mark_order_as_done_and_set_delivery_method\n+    when :delivery_ordered\n+      update_order_delivery_info_and_delivery_method\n+    end\n   end\n+\n+  private\n+\n+    def update_order_customer_and_product_info\n+      customer = @huutokauppa_mail.find_customer || @huutokauppa_mail.create_customer","path":"app/jobs/huutokauppa_job.rb","position":29,"original_position":29,"commit_id":"5b0cbe97c2feb30cd9d61e7246ff47407213c1b7","original_commit_id":"5b0cbe97c2feb30cd9d61e7246ff47407213c1b7","user":{"login":"jonikanerva","id":679717,"avatar_url":"https://avatars.githubusercontent.com/u/679717?v=3","gravatar_id":"","url":"https://api.github.com/users/jonikanerva","html_url":"https://github.com/jonikanerva","followers_url":"https://api.github.com/users/jonikanerva/followers","following_url":"https://api.github.com/users/jonikanerva/following{/other_user}","gists_url":"https://api.github.com/users/jonikanerva/gists{/gist_id}","starred_url":"https://api.github.com/users/jonikanerva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonikanerva/subscriptions","organizations_url":"https://api.github.com/users/jonikanerva/orgs","repos_url":"https://api.github.com/users/jonikanerva/repos","events_url":"https://api.github.com/users/jonikanerva/events{/privacy}","received_events_url":"https://api.github.com/users/jonikanerva/received_events","type":"User","site_admin":false},"body":"Tässä on turha muuttuja `customer`. Lisäksi voisi olla selkeämpää, että tämäkin olisi `HuutokauppaMail`:in asioita, ts. tämä olisi vain `@huutokauppa_mail.update_customer`, joka sitten hoitaisi tuon find || create logiikan.","created_at":"2016-04-29T10:46:09Z","updated_at":"2016-04-29T10:46:09Z","html_url":"https://github.com/devlab-oy/pupenext/pull/230#discussion_r61560388","pull_request_url":"https://api.github.com/repos/devlab-oy/pupenext/pulls/230","_links":{"self":{"href":"https://api.github.com/repos/devlab-oy/pupenext/pulls/comments/61560388"},"html":{"href":"https://github.com/devlab-oy/pupenext/pull/230#discussion_r61560388"},"pull_request":{"href":"https://api.github.com/repos/devlab-oy/pupenext/pulls/230"}}},"pull_request":{"url":"https://api.github.com/repos/devlab-oy/pupenext/pulls/230","id":68330796,"html_url":"https://github.com/devlab-oy/pupenext/pull/230","diff_url":"https://github.com/devlab-oy/pupenext/pull/230.diff","patch_url":"https://github.com/devlab-oy/pupenext/pull/230.patch","issue_url":"https://api.github.com/repos/devlab-oy/pupenext/issues/230","number":230,"state":"open","locked":false,"title":"HuutokauppaJob logic","user":{"login":"tiere","id":3338413,"avatar_url":"https://avatars.githubusercontent.com/u/3338413?v=3","gravatar_id":"","url":"https://api.github.com/users/tiere","html_url":"https://github.com/tiere","followers_url":"https://api.github.com/users/tiere/followers","following_url":"https://api.github.com/users/tiere/following{/other_user}","gists_url":"https://api.github.com/users/tiere/gists{/gist_id}","starred_url":"https://api.github.com/users/tiere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tiere/subscriptions","organizations_url":"https://api.github.com/users/tiere/orgs","repos_url":"https://api.github.com/users/tiere/repos","events_url":"https://api.github.com/users/tiere/events{/privacy}","received_events_url":"https://api.github.com/users/tiere/received_events","type":"User","site_admin":false},"body":"- Process `offer_accepted` and `offer_automatically_accepted` emails in `HuutokauppaJob`\r\n- Process `purchase_price_paid` emails in `HuutokauppaJob`\r\n- Process `delivery_ordered` emails in `HuutokauppaJob`\r\n- Log exceptions in `HuutokauppaJob`\r\n- Use Pupesoft function `lisaa_rivi` in `add_delivery_row`\r\n- Add correct delivery row for order according to new logic","created_at":"2016-04-29T06:51:57Z","updated_at":"2016-04-29T10:46:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c93ba8e64d3e63b54dd45d0c6b07e87626e48a12","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/devlab-oy/pupenext/pulls/230/commits","review_comments_url":"https://api.github.com/repos/devlab-oy/pupenext/pulls/230/comments","review_comment_url":"https://api.github.com/repos/devlab-oy/pupenext/pulls/comments{/number}","comments_url":"https://api.github.com/repos/devlab-oy/pupenext/issues/230/comments","statuses_url":"https://api.github.com/repos/devlab-oy/pupenext/statuses/5b0cbe97c2feb30cd9d61e7246ff47407213c1b7","head":{"label":"devlab-oy:tommi/huutokauppa-job-logic","ref":"tommi/huutokauppa-job-logic","sha":"5b0cbe97c2feb30cd9d61e7246ff47407213c1b7","user":{"login":"devlab-oy","id":679728,"avatar_url":"https://avatars.githubusercontent.com/u/679728?v=3","gravatar_id":"","url":"https://api.github.com/users/devlab-oy","html_url":"https://github.com/devlab-oy","followers_url":"https://api.github.com/users/devlab-oy/followers","following_url":"https://api.github.com/users/devlab-oy/following{/other_user}","gists_url":"https://api.github.com/users/devlab-oy/gists{/gist_id}","starred_url":"https://api.github.com/users/devlab-oy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devlab-oy/subscriptions","organizations_url":"https://api.github.com/users/devlab-oy/orgs","repos_url":"https://api.github.com/users/devlab-oy/repos","events_url":"https://api.github.com/users/devlab-oy/events{/privacy}","received_events_url":"https://api.github.com/users/devlab-oy/received_events","type":"Organization","site_admin":false},"repo":{"id":15131726,"name":"pupenext","full_name":"devlab-oy/pupenext","owner":{"login":"devlab-oy","id":679728,"avatar_url":"https://avatars.githubusercontent.com/u/679728?v=3","gravatar_id":"","url":"https://api.github.com/users/devlab-oy","html_url":"https://github.com/devlab-oy","followers_url":"https://api.github.com/users/devlab-oy/followers","following_url":"https://api.github.com/users/devlab-oy/following{/other_user}","gists_url":"https://api.github.com/users/devlab-oy/gists{/gist_id}","starred_url":"https://api.github.com/users/devlab-oy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devlab-oy/subscriptions","organizations_url":"https://api.github.com/users/devlab-oy/orgs","repos_url":"https://api.github.com/users/devlab-oy/repos","events_url":"https://api.github.com/users/devlab-oy/events{/privacy}","received_events_url":"https://api.github.com/users/devlab-oy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/devlab-oy/pupenext","description":"Ruby on Rails implementaatio Pupesoft -toiminnanohjausjärjestelmästä.","fork":false,"url":"https://api.github.com/repos/devlab-oy/pupenext","forks_url":"https://api.github.com/repos/devlab-oy/pupenext/forks","keys_url":"https://api.github.com/repos/devlab-oy/pupenext/keys{/key_id}","collaborators_url":"https://api.github.com/repos/devlab-oy/pupenext/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/devlab-oy/pupenext/teams","hooks_url":"https://api.github.com/repos/devlab-oy/pupenext/hooks","issue_events_url":"https://api.github.com/repos/devlab-oy/pupenext/issues/events{/number}","events_url":"https://api.github.com/repos/devlab-oy/pupenext/events","assignees_url":"https://api.github.com/repos/devlab-oy/pupenext/assignees{/user}","branches_url":"https://api.github.com/repos/devlab-oy/pupenext/branches{/branch}","tags_url":"https://api.github.com/repos/devlab-oy/pupenext/tags","blobs_url":"https://api.github.com/repos/devlab-oy/pupenext/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/devlab-oy/pupenext/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/devlab-oy/pupenext/git/refs{/sha}","trees_url":"https://api.github.com/repos/devlab-oy/pupenext/git/trees{/sha}","statuses_url":"https://api.github.com/repos/devlab-oy/pupenext/statuses/{sha}","languages_url":"https://api.github.com/repos/devlab-oy/pupenext/languages","stargazers_url":"https://api.github.com/repos/devlab-oy/pupenext/stargazers","contributors_url":"https://api.github.com/repos/devlab-oy/pupenext/contributors","subscribers_url":"https://api.github.com/repos/devlab-oy/pupenext/subscribers","subscription_url":"https://api.github.com/repos/devlab-oy/pupenext/subscription","commits_url":"https://api.github.com/repos/devlab-oy/pupenext/commits{/sha}","git_commits_url":"https://api.github.com/repos/devlab-oy/pupenext/git/commits{/sha}","comments_url":"https://api.github.com/repos/devlab-oy/pupenext/comments{/number}","issue_comment_url":"https://api.github.com/repos/devlab-oy/pupenext/issues/comments{/number}","contents_url":"https://api.github.com/repos/devlab-oy/pupenext/contents/{+path}","compare_url":"https://api.github.com/repos/devlab-oy/pupenext/compare/{base}...{head}","merges_url":"https://api.github.com/repos/devlab-oy/pupenext/merges","archive_url":"https://api.github.com/repos/devlab-oy/pupenext/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/devlab-oy/pupenext/downloads","issues_url":"https://api.github.com/repos/devlab-oy/pupenext/issues{/number}","pulls_url":"https://api.github.com/repos/devlab-oy/pupenext/pulls{/number}","milestones_url":"https://api.github.com/repos/devlab-oy/pupenext/milestones{/number}","notifications_url":"https://api.github.com/repos/devlab-oy/pupenext/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/devlab-oy/pupenext/labels{/name}","releases_url":"https://api.github.com/repos/devlab-oy/pupenext/releases{/id}","deployments_url":"https://api.github.com/repos/devlab-oy/pupenext/deployments","created_at":"2013-12-12T09:22:06Z","updated_at":"2016-01-12T14:06:17Z","pushed_at":"2016-04-29T09:36:27Z","git_url":"git://github.com/devlab-oy/pupenext.git","ssh_url":"git@github.com:devlab-oy/pupenext.git","clone_url":"https://github.com/devlab-oy/pupenext.git","svn_url":"https://github.com/devlab-oy/pupenext","homepage":"www.devlab.fi","size":4934,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":3,"default_branch":"master"}},"base":{"label":"devlab-oy:master","ref":"master","sha":"1703b53d46f52eb64bbada8c0e04bd53502b2988","user":{"login":"devlab-oy","id":679728,"avatar_url":"https://avatars.githubusercontent.com/u/679728?v=3","gravatar_id":"","url":"https://api.github.com/users/devlab-oy","html_url":"https://github.com/devlab-oy","followers_url":"https://api.github.com/users/devlab-oy/followers","following_url":"https://api.github.com/users/devlab-oy/following{/other_user}","gists_url":"https://api.github.com/users/devlab-oy/gists{/gist_id}","starred_url":"https://api.github.com/users/devlab-oy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devlab-oy/subscriptions","organizations_url":"https://api.github.com/users/devlab-oy/orgs","repos_url":"https://api.github.com/users/devlab-oy/repos","events_url":"https://api.github.com/users/devlab-oy/events{/privacy}","received_events_url":"https://api.github.com/users/devlab-oy/received_events","type":"Organization","site_admin":false},"repo":{"id":15131726,"name":"pupenext","full_name":"devlab-oy/pupenext","owner":{"login":"devlab-oy","id":679728,"avatar_url":"https://avatars.githubusercontent.com/u/679728?v=3","gravatar_id":"","url":"https://api.github.com/users/devlab-oy","html_url":"https://github.com/devlab-oy","followers_url":"https://api.github.com/users/devlab-oy/followers","following_url":"https://api.github.com/users/devlab-oy/following{/other_user}","gists_url":"https://api.github.com/users/devlab-oy/gists{/gist_id}","starred_url":"https://api.github.com/users/devlab-oy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devlab-oy/subscriptions","organizations_url":"https://api.github.com/users/devlab-oy/orgs","repos_url":"https://api.github.com/users/devlab-oy/repos","events_url":"https://api.github.com/users/devlab-oy/events{/privacy}","received_events_url":"https://api.github.com/users/devlab-oy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/devlab-oy/pupenext","description":"Ruby on Rails implementaatio Pupesoft -toiminnanohjausjärjestelmästä.","fork":false,"url":"https://api.github.com/repos/devlab-oy/pupenext","forks_url":"https://api.github.com/repos/devlab-oy/pupenext/forks","keys_url":"https://api.github.com/repos/devlab-oy/pupenext/keys{/key_id}","collaborators_url":"https://api.github.com/repos/devlab-oy/pupenext/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/devlab-oy/pupenext/teams","hooks_url":"https://api.github.com/repos/devlab-oy/pupenext/hooks","issue_events_url":"https://api.github.com/repos/devlab-oy/pupenext/issues/events{/number}","events_url":"https://api.github.com/repos/devlab-oy/pupenext/events","assignees_url":"https://api.github.com/repos/devlab-oy/pupenext/assignees{/user}","branches_url":"https://api.github.com/repos/devlab-oy/pupenext/branches{/branch}","tags_url":"https://api.github.com/repos/devlab-oy/pupenext/tags","blobs_url":"https://api.github.com/repos/devlab-oy/pupenext/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/devlab-oy/pupenext/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/devlab-oy/pupenext/git/refs{/sha}","trees_url":"https://api.github.com/repos/devlab-oy/pupenext/git/trees{/sha}","statuses_url":"https://api.github.com/repos/devlab-oy/pupenext/statuses/{sha}","languages_url":"https://api.github.com/repos/devlab-oy/pupenext/languages","stargazers_url":"https://api.github.com/repos/devlab-oy/pupenext/stargazers","contributors_url":"https://api.github.com/repos/devlab-oy/pupenext/contributors","subscribers_url":"https://api.github.com/repos/devlab-oy/pupenext/subscribers","subscription_url":"https://api.github.com/repos/devlab-oy/pupenext/subscription","commits_url":"https://api.github.com/repos/devlab-oy/pupenext/commits{/sha}","git_commits_url":"https://api.github.com/repos/devlab-oy/pupenext/git/commits{/sha}","comments_url":"https://api.github.com/repos/devlab-oy/pupenext/comments{/number}","issue_comment_url":"https://api.github.com/repos/devlab-oy/pupenext/issues/comments{/number}","contents_url":"https://api.github.com/repos/devlab-oy/pupenext/contents/{+path}","compare_url":"https://api.github.com/repos/devlab-oy/pupenext/compare/{base}...{head}","merges_url":"https://api.github.com/repos/devlab-oy/pupenext/merges","archive_url":"https://api.github.com/repos/devlab-oy/pupenext/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/devlab-oy/pupenext/downloads","issues_url":"https://api.github.com/repos/devlab-oy/pupenext/issues{/number}","pulls_url":"https://api.github.com/repos/devlab-oy/pupenext/pulls{/number}","milestones_url":"https://api.github.com/repos/devlab-oy/pupenext/milestones{/number}","notifications_url":"https://api.github.com/repos/devlab-oy/pupenext/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/devlab-oy/pupenext/labels{/name}","releases_url":"https://api.github.com/repos/devlab-oy/pupenext/releases{/id}","deployments_url":"https://api.github.com/repos/devlab-oy/pupenext/deployments","created_at":"2013-12-12T09:22:06Z","updated_at":"2016-01-12T14:06:17Z","pushed_at":"2016-04-29T09:36:27Z","git_url":"git://github.com/devlab-oy/pupenext.git","ssh_url":"git@github.com:devlab-oy/pupenext.git","clone_url":"https://github.com/devlab-oy/pupenext.git","svn_url":"https://github.com/devlab-oy/pupenext","homepage":"www.devlab.fi","size":4934,"stargazers_count":3,"watchers_count":3,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/devlab-oy/pupenext/pulls/230"},"html":{"href":"https://github.com/devlab-oy/pupenext/pull/230"},"issue":{"href":"https://api.github.com/repos/devlab-oy/pupenext/issues/230"},"comments":{"href":"https://api.github.com/repos/devlab-oy/pupenext/issues/230/comments"},"review_comments":{"href":"https://api.github.com/repos/devlab-oy/pupenext/pulls/230/comments"},"review_comment":{"href":"https://api.github.com/repos/devlab-oy/pupenext/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/devlab-oy/pupenext/pulls/230/commits"},"statuses":{"href":"https://api.github.com/repos/devlab-oy/pupenext/statuses/5b0cbe97c2feb30cd9d61e7246ff47407213c1b7"}}}}