{"action":"created","comment":{"url":"https://api.github.com/repos/ryuzee/SlideHub/pulls/comments/54360371","id":54360371,"diff_hunk":"@@ -0,0 +1,156 @@\n+require 'azure'\n+require 'azure-contrib'\n+require 'json'\n+\n+class AzureEngine\n+  class Config\n+    include ActiveSupport::Configurable\n+    config_accessor :bucket_name\n+    config_accessor :image_bucket_name\n+    config_accessor :cdn_base_url\n+    config_accessor :queue_name\n+    config_accessor :azure_storage_access_key\n+    config_accessor :azure_storage_account_name\n+  end\n+\n+  def self.configure(&block)\n+    yield config\n+    Azure.config.storage_account_name = @config.azure_storage_account_name\n+    Azure.config.storage_access_key = @config.azure_storage_access_key\n+  end\n+\n+  def self.config\n+    @config ||= Config.new\n+  end\n+\n+  def self.queue_endpoint\n+    url = \"https://#{@config.azure_storage_account_name}.queue.core.windows.net/\"\n+    url\n+  end\n+\n+  def self.resource_endpoint\n+    unless @config.cdn_base_url.blank?\n+      url = @config.cdn_base_url\n+    else\n+      url = \"https://#{@config.azure_storage_account_name}.blob.core.windows.net/#{@config.image_bucket_name}\"\n+    end\n+    url\n+  end\n+\n+  def self.upload_endpoint\n+    url = \"https://#{@config.azure_storage_account_name}.blob.core.windows.net/#{@config.bucket_name}\"\n+    url\n+  end\n+\n+  def self.send_message(message)\n+    queues = Azure.queues\n+    resp = queues.create_message(@config.queue_name, message)\n+    resp\n+  end\n+\n+  def self.receive_message(max_number = 10)\n+    queues = Azure.queues\n+    res = queues.list_messages(@config.queue_name, 600, {:number_of_messages => max_number})\n+    res\n+  end\n+\n+  def self.message_exist?(resp)\n+    if !resp || resp.count == 0\n+      false\n+    else\n+      true\n+    end\n+  end\n+\n+  def self.delete_message(message_object)\n+    queues = Azure.queues\n+    resp = queues.delete_message(@config.queue_name, message_object.id, message_object.pop_receipt)\n+    resp\n+  end\n+\n+  def self.batch_delete(entries)\n+    entries.each do |entry|\n+      self.delete_message(entry)\n+    end\n+  end\n+\n+  ## Blob\n+  def self.upload_files(container, files, prefix)\n+    bs = Azure::Blob::BlobService.new\n+    files.each do |f|\n+      if File.exist?(f)\n+        content = File.open(f, 'rb') { |file| file.read }\n+        bs.create_block_blob(container, \"#{prefix}/#{File.basename(f)}\", content)\n+      end\n+    end\n+  end\n+\n+  def self.get_file_list(container, prefix)\n+    bs = Azure::Blob::BlobService.new\n+    resp = bs.list_blobs(container, { :prefix => prefix, :max_results => 1000 })\n+    files = []\n+    resp.each do |blob|\n+      files.push({ key: blob.name })\n+    end\n+    files\n+  end\n+\n+  def self.save_file(container, key, destination)\n+    bs = Azure::Blob::BlobService.new\n+    blob, content = bs.get_blob(container, key)\n+    File.open(destination, \"wb\") {|f| f.write(content)}\n+  end\n+\n+  def self.delete_slide(key)\n+    if key.empty?\n+      return false\n+    end\n+    files = self.get_file_list(@config.bucket_name, key)\n+    self.delete_files(@config.bucket_name, files)\n+    true\n+  end\n+\n+  def self.delete_generated_files(key)\n+    if key.empty?\n+      return false\n+    end\n+    files = self.get_file_list(@config.image_bucket_name, key)\n+    self.delete_files(@config.image_bucket_name, files)\n+    true\n+  end\n+\n+  def self.get_slide_download_url(key)\n+    self.get_download_url(@config.bucket_name, key)\n+  end\n+\n+  def self.delete_files(container, files)\n+    bs = Azure::Blob::BlobService.new\n+    files.each do |f|\n+      bs.delete_blob(container, f)\n+    end\n+  end\n+\n+  def self.get_download_url(container, key)","path":"app/models/azure_engine.rb","position":133,"original_position":133,"commit_id":"12ed3d523a131a191c879b86d5de18e63273b971","original_commit_id":"12ed3d523a131a191c879b86d5de18e63273b971","user":{"login":"ryuzee","id":272013,"avatar_url":"https://avatars.githubusercontent.com/u/272013?v=3","gravatar_id":"","url":"https://api.github.com/users/ryuzee","html_url":"https://github.com/ryuzee","followers_url":"https://api.github.com/users/ryuzee/followers","following_url":"https://api.github.com/users/ryuzee/following{/other_user}","gists_url":"https://api.github.com/users/ryuzee/gists{/gist_id}","starred_url":"https://api.github.com/users/ryuzee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryuzee/subscriptions","organizations_url":"https://api.github.com/users/ryuzee/orgs","repos_url":"https://api.github.com/users/ryuzee/repos","events_url":"https://api.github.com/users/ryuzee/events{/privacy}","received_events_url":"https://api.github.com/users/ryuzee/received_events","type":"User","site_admin":false},"body":"__[reek]__\n* [UnusedParameters] has unused parameter 'container' [:ref](https://github.com/troessner/reek/blob/master/docs/Unused-Parameters.md)","created_at":"2016-02-29T00:29:47Z","updated_at":"2016-02-29T00:29:47Z","html_url":"https://github.com/ryuzee/SlideHub/pull/39#discussion_r54360371","pull_request_url":"https://api.github.com/repos/ryuzee/SlideHub/pulls/39","_links":{"self":{"href":"https://api.github.com/repos/ryuzee/SlideHub/pulls/comments/54360371"},"html":{"href":"https://github.com/ryuzee/SlideHub/pull/39#discussion_r54360371"},"pull_request":{"href":"https://api.github.com/repos/ryuzee/SlideHub/pulls/39"}}},"pull_request":{"url":"https://api.github.com/repos/ryuzee/SlideHub/pulls/39","id":60990871,"html_url":"https://github.com/ryuzee/SlideHub/pull/39","diff_url":"https://github.com/ryuzee/SlideHub/pull/39.diff","patch_url":"https://github.com/ryuzee/SlideHub/pull/39.patch","issue_url":"https://api.github.com/repos/ryuzee/SlideHub/issues/39","number":39,"state":"open","locked":false,"title":"Apply Azure","user":{"login":"ryuzee","id":272013,"avatar_url":"https://avatars.githubusercontent.com/u/272013?v=3","gravatar_id":"","url":"https://api.github.com/users/ryuzee","html_url":"https://github.com/ryuzee","followers_url":"https://api.github.com/users/ryuzee/followers","following_url":"https://api.github.com/users/ryuzee/following{/other_user}","gists_url":"https://api.github.com/users/ryuzee/gists{/gist_id}","starred_url":"https://api.github.com/users/ryuzee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryuzee/subscriptions","organizations_url":"https://api.github.com/users/ryuzee/orgs","repos_url":"https://api.github.com/users/ryuzee/repos","events_url":"https://api.github.com/users/ryuzee/events{/privacy}","received_events_url":"https://api.github.com/users/ryuzee/received_events","type":"User","site_admin":false},"body":"* Enables to use Azure for storage!!","created_at":"2016-02-28T13:07:33Z","updated_at":"2016-02-29T00:29:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"17334e491a53cad73df813c6458480961e9e11c3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ryuzee/SlideHub/pulls/39/commits","review_comments_url":"https://api.github.com/repos/ryuzee/SlideHub/pulls/39/comments","review_comment_url":"https://api.github.com/repos/ryuzee/SlideHub/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ryuzee/SlideHub/issues/39/comments","statuses_url":"https://api.github.com/repos/ryuzee/SlideHub/statuses/12ed3d523a131a191c879b86d5de18e63273b971","head":{"label":"ryuzee:azure","ref":"azure","sha":"12ed3d523a131a191c879b86d5de18e63273b971","user":{"login":"ryuzee","id":272013,"avatar_url":"https://avatars.githubusercontent.com/u/272013?v=3","gravatar_id":"","url":"https://api.github.com/users/ryuzee","html_url":"https://github.com/ryuzee","followers_url":"https://api.github.com/users/ryuzee/followers","following_url":"https://api.github.com/users/ryuzee/following{/other_user}","gists_url":"https://api.github.com/users/ryuzee/gists{/gist_id}","starred_url":"https://api.github.com/users/ryuzee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryuzee/subscriptions","organizations_url":"https://api.github.com/users/ryuzee/orgs","repos_url":"https://api.github.com/users/ryuzee/repos","events_url":"https://api.github.com/users/ryuzee/events{/privacy}","received_events_url":"https://api.github.com/users/ryuzee/received_events","type":"User","site_admin":false},"repo":{"id":47168038,"name":"SlideHub","full_name":"ryuzee/SlideHub","owner":{"login":"ryuzee","id":272013,"avatar_url":"https://avatars.githubusercontent.com/u/272013?v=3","gravatar_id":"","url":"https://api.github.com/users/ryuzee","html_url":"https://github.com/ryuzee","followers_url":"https://api.github.com/users/ryuzee/followers","following_url":"https://api.github.com/users/ryuzee/following{/other_user}","gists_url":"https://api.github.com/users/ryuzee/gists{/gist_id}","starred_url":"https://api.github.com/users/ryuzee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryuzee/subscriptions","organizations_url":"https://api.github.com/users/ryuzee/orgs","repos_url":"https://api.github.com/users/ryuzee/repos","events_url":"https://api.github.com/users/ryuzee/events{/privacy}","received_events_url":"https://api.github.com/users/ryuzee/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ryuzee/SlideHub","description":"SlideHub is an Open Source Slide Sharing Application","fork":false,"url":"https://api.github.com/repos/ryuzee/SlideHub","forks_url":"https://api.github.com/repos/ryuzee/SlideHub/forks","keys_url":"https://api.github.com/repos/ryuzee/SlideHub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ryuzee/SlideHub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ryuzee/SlideHub/teams","hooks_url":"https://api.github.com/repos/ryuzee/SlideHub/hooks","issue_events_url":"https://api.github.com/repos/ryuzee/SlideHub/issues/events{/number}","events_url":"https://api.github.com/repos/ryuzee/SlideHub/events","assignees_url":"https://api.github.com/repos/ryuzee/SlideHub/assignees{/user}","branches_url":"https://api.github.com/repos/ryuzee/SlideHub/branches{/branch}","tags_url":"https://api.github.com/repos/ryuzee/SlideHub/tags","blobs_url":"https://api.github.com/repos/ryuzee/SlideHub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ryuzee/SlideHub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ryuzee/SlideHub/git/refs{/sha}","trees_url":"https://api.github.com/repos/ryuzee/SlideHub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ryuzee/SlideHub/statuses/{sha}","languages_url":"https://api.github.com/repos/ryuzee/SlideHub/languages","stargazers_url":"https://api.github.com/repos/ryuzee/SlideHub/stargazers","contributors_url":"https://api.github.com/repos/ryuzee/SlideHub/contributors","subscribers_url":"https://api.github.com/repos/ryuzee/SlideHub/subscribers","subscription_url":"https://api.github.com/repos/ryuzee/SlideHub/subscription","commits_url":"https://api.github.com/repos/ryuzee/SlideHub/commits{/sha}","git_commits_url":"https://api.github.com/repos/ryuzee/SlideHub/git/commits{/sha}","comments_url":"https://api.github.com/repos/ryuzee/SlideHub/comments{/number}","issue_comment_url":"https://api.github.com/repos/ryuzee/SlideHub/issues/comments{/number}","contents_url":"https://api.github.com/repos/ryuzee/SlideHub/contents/{+path}","compare_url":"https://api.github.com/repos/ryuzee/SlideHub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ryuzee/SlideHub/merges","archive_url":"https://api.github.com/repos/ryuzee/SlideHub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ryuzee/SlideHub/downloads","issues_url":"https://api.github.com/repos/ryuzee/SlideHub/issues{/number}","pulls_url":"https://api.github.com/repos/ryuzee/SlideHub/pulls{/number}","milestones_url":"https://api.github.com/repos/ryuzee/SlideHub/milestones{/number}","notifications_url":"https://api.github.com/repos/ryuzee/SlideHub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ryuzee/SlideHub/labels{/name}","releases_url":"https://api.github.com/repos/ryuzee/SlideHub/releases{/id}","deployments_url":"https://api.github.com/repos/ryuzee/SlideHub/deployments","created_at":"2015-12-01T05:36:48Z","updated_at":"2016-02-19T02:13:09Z","pushed_at":"2016-02-29T00:29:34Z","git_url":"git://github.com/ryuzee/SlideHub.git","ssh_url":"git@github.com:ryuzee/SlideHub.git","clone_url":"https://github.com/ryuzee/SlideHub.git","svn_url":"https://github.com/ryuzee/SlideHub","homepage":"http://www.ryuzee.com","size":5704,"stargazers_count":14,"watchers_count":14,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":14,"default_branch":"master"}},"base":{"label":"ryuzee:master","ref":"master","sha":"c79d0d6bf680e49ecfd88ed377175916c9f48f02","user":{"login":"ryuzee","id":272013,"avatar_url":"https://avatars.githubusercontent.com/u/272013?v=3","gravatar_id":"","url":"https://api.github.com/users/ryuzee","html_url":"https://github.com/ryuzee","followers_url":"https://api.github.com/users/ryuzee/followers","following_url":"https://api.github.com/users/ryuzee/following{/other_user}","gists_url":"https://api.github.com/users/ryuzee/gists{/gist_id}","starred_url":"https://api.github.com/users/ryuzee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryuzee/subscriptions","organizations_url":"https://api.github.com/users/ryuzee/orgs","repos_url":"https://api.github.com/users/ryuzee/repos","events_url":"https://api.github.com/users/ryuzee/events{/privacy}","received_events_url":"https://api.github.com/users/ryuzee/received_events","type":"User","site_admin":false},"repo":{"id":47168038,"name":"SlideHub","full_name":"ryuzee/SlideHub","owner":{"login":"ryuzee","id":272013,"avatar_url":"https://avatars.githubusercontent.com/u/272013?v=3","gravatar_id":"","url":"https://api.github.com/users/ryuzee","html_url":"https://github.com/ryuzee","followers_url":"https://api.github.com/users/ryuzee/followers","following_url":"https://api.github.com/users/ryuzee/following{/other_user}","gists_url":"https://api.github.com/users/ryuzee/gists{/gist_id}","starred_url":"https://api.github.com/users/ryuzee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ryuzee/subscriptions","organizations_url":"https://api.github.com/users/ryuzee/orgs","repos_url":"https://api.github.com/users/ryuzee/repos","events_url":"https://api.github.com/users/ryuzee/events{/privacy}","received_events_url":"https://api.github.com/users/ryuzee/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ryuzee/SlideHub","description":"SlideHub is an Open Source Slide Sharing Application","fork":false,"url":"https://api.github.com/repos/ryuzee/SlideHub","forks_url":"https://api.github.com/repos/ryuzee/SlideHub/forks","keys_url":"https://api.github.com/repos/ryuzee/SlideHub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ryuzee/SlideHub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ryuzee/SlideHub/teams","hooks_url":"https://api.github.com/repos/ryuzee/SlideHub/hooks","issue_events_url":"https://api.github.com/repos/ryuzee/SlideHub/issues/events{/number}","events_url":"https://api.github.com/repos/ryuzee/SlideHub/events","assignees_url":"https://api.github.com/repos/ryuzee/SlideHub/assignees{/user}","branches_url":"https://api.github.com/repos/ryuzee/SlideHub/branches{/branch}","tags_url":"https://api.github.com/repos/ryuzee/SlideHub/tags","blobs_url":"https://api.github.com/repos/ryuzee/SlideHub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ryuzee/SlideHub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ryuzee/SlideHub/git/refs{/sha}","trees_url":"https://api.github.com/repos/ryuzee/SlideHub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ryuzee/SlideHub/statuses/{sha}","languages_url":"https://api.github.com/repos/ryuzee/SlideHub/languages","stargazers_url":"https://api.github.com/repos/ryuzee/SlideHub/stargazers","contributors_url":"https://api.github.com/repos/ryuzee/SlideHub/contributors","subscribers_url":"https://api.github.com/repos/ryuzee/SlideHub/subscribers","subscription_url":"https://api.github.com/repos/ryuzee/SlideHub/subscription","commits_url":"https://api.github.com/repos/ryuzee/SlideHub/commits{/sha}","git_commits_url":"https://api.github.com/repos/ryuzee/SlideHub/git/commits{/sha}","comments_url":"https://api.github.com/repos/ryuzee/SlideHub/comments{/number}","issue_comment_url":"https://api.github.com/repos/ryuzee/SlideHub/issues/comments{/number}","contents_url":"https://api.github.com/repos/ryuzee/SlideHub/contents/{+path}","compare_url":"https://api.github.com/repos/ryuzee/SlideHub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ryuzee/SlideHub/merges","archive_url":"https://api.github.com/repos/ryuzee/SlideHub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ryuzee/SlideHub/downloads","issues_url":"https://api.github.com/repos/ryuzee/SlideHub/issues{/number}","pulls_url":"https://api.github.com/repos/ryuzee/SlideHub/pulls{/number}","milestones_url":"https://api.github.com/repos/ryuzee/SlideHub/milestones{/number}","notifications_url":"https://api.github.com/repos/ryuzee/SlideHub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ryuzee/SlideHub/labels{/name}","releases_url":"https://api.github.com/repos/ryuzee/SlideHub/releases{/id}","deployments_url":"https://api.github.com/repos/ryuzee/SlideHub/deployments","created_at":"2015-12-01T05:36:48Z","updated_at":"2016-02-19T02:13:09Z","pushed_at":"2016-02-29T00:29:34Z","git_url":"git://github.com/ryuzee/SlideHub.git","ssh_url":"git@github.com:ryuzee/SlideHub.git","clone_url":"https://github.com/ryuzee/SlideHub.git","svn_url":"https://github.com/ryuzee/SlideHub","homepage":"http://www.ryuzee.com","size":5704,"stargazers_count":14,"watchers_count":14,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":14,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ryuzee/SlideHub/pulls/39"},"html":{"href":"https://github.com/ryuzee/SlideHub/pull/39"},"issue":{"href":"https://api.github.com/repos/ryuzee/SlideHub/issues/39"},"comments":{"href":"https://api.github.com/repos/ryuzee/SlideHub/issues/39/comments"},"review_comments":{"href":"https://api.github.com/repos/ryuzee/SlideHub/pulls/39/comments"},"review_comment":{"href":"https://api.github.com/repos/ryuzee/SlideHub/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ryuzee/SlideHub/pulls/39/commits"},"statuses":{"href":"https://api.github.com/repos/ryuzee/SlideHub/statuses/12ed3d523a131a191c879b86d5de18e63273b971"}}}}