asana-god-contact 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 36ff2cc889884079ad2a83bc107ed60fcb7e58ba
4
+ data.tar.gz: 13d101f1fc2648a05fb2341c411a10b33199d665
5
+ SHA512:
6
+ metadata.gz: 46a57e5122407d8a0e5889c03a1874fe9adce1c1292d3b5254e91d235a44399c96e823c1de19ccc443a8a9ae81531e7d52c8bd6e8f2a4b4e66aac1d0c56031a9
7
+ data.tar.gz: 0132587f6be56ed2a8d3f5f0b32f20f60f1dcc2255a75f20cd698394a9c71617f8fc6ae534422f7c609e94d43bac4b169c290b24c7af1ff233d2f2c0a6126d7c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in asana_god_contact.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem "minitest"
8
+ gem "rake"
9
+ gem 'rspec-core'
10
+ gem "mocha"
11
+ end
@@ -0,0 +1,49 @@
1
+ # AsanaGodContact
2
+
3
+ A God::Contacts class for sending notifications to Asana
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'asana-god-contact'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install asana-god-contact
20
+
21
+ ## Usage
22
+
23
+ Configure our god file to use asana connector adding next code
24
+ ```ruby
25
+ require 'asana-god-contact'
26
+
27
+ God.contact(:asana) do |c|
28
+ c.name = 'asana'
29
+ c.api_key = "2D2R..........OG0iZru"
30
+ c.workspace_id = "49.....860"
31
+ c.assignee = "92.....302"
32
+ c.projects = "28.....959"
33
+ c.folowers = "92.....302"
34
+ end
35
+ ```
36
+ where "api_key" is the key you get from your asana
37
+
38
+ Other params are apropriate ids of workspace, user, project and followers. Followers can be an array.
39
+
40
+ Add the name of your contact (c.name = 'asana') to be used as notification:
41
+
42
+ ```ruby
43
+ w.start_if do |start|
44
+ start.condition(:process_running) do |c|
45
+ c.running = false
46
+ c.notify = ['asana']
47
+ end
48
+ end
49
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'asana-god-contact/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "asana-god-contact"
8
+ spec.version = AsanaGodContact::VERSION
9
+ spec.authors = ["Roman Rott"]
10
+ spec.email = ["roman.rott@gmail.com"]
11
+
12
+ spec.summary = "A God::Contacts class for sending notifications to Asana"
13
+ spec.description = "Allows to send notifications to Asana"
14
+ spec.homepage = "https://github.com/rrott/asana-god-contact"
15
+ spec.license = "GPL"
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "god", "~> 0.13"
21
+ spec.add_dependency "sys-proctable", "~>0.9"
22
+ spec.add_dependency "json", "~>1.8"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.9"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "mocha", '~> 1'
27
+ spec.add_development_dependency "minitest", '~> 5.7'
28
+
29
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "asana-god-contact"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,49 @@
1
+ require 'god'
2
+ require 'asana-god-contact/version'
3
+ require 'asana-god-contact/config'
4
+ require 'asana-god-contact/asana_connector'
5
+
6
+ module God
7
+ module Contacts
8
+ class Asana < Contact
9
+ class << self
10
+ attr_accessor :api_key, :workspace_id, :assignee, :projects, :folowers
11
+ attr_accessor :format
12
+ end
13
+
14
+ self.format = lambda do |message, time, priority, category, host|
15
+ "[#{time}] #{host} - #{message}"
16
+ end
17
+
18
+ def valid?
19
+ valid = true
20
+ AsanaGodContact::Config::PARAMS.each do |param|
21
+ valid &= complain("Attribute #{param} must be specified", self) unless arg(param)
22
+ end
23
+ valid
24
+ end
25
+
26
+ attr_accessor :api_key, :workspace_id, :assignee, :projects, :folowers
27
+
28
+ def notify(message, time, priority, category, host)
29
+ body = Asana.format.call(message, time, priority, category, host)
30
+
31
+ connection = AsanaGodContact::Connector.new(
32
+ :api_key => arg(:api_key),
33
+ :workspace_id => arg(:workspace_id),
34
+ :assignee => arg(:assignee),
35
+ :projects => arg(:projects),
36
+ :folowers => arg(:folowers),
37
+ :message => body
38
+ )
39
+
40
+ connection.create_task
41
+
42
+ self.info = "notified asana: #{arg(:workspace_id)}, #{arg(:assignee)}, project #{arg(:project)}"
43
+ rescue Object => e
44
+ applog(nil, :info, "Failed to notify Asana: #{arg(:workspace_id)}, #{arg(:assignee)}, project #{arg(:project)}" )
45
+ applog(nil, :debug, e.backtrace.join("\n"))
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,50 @@
1
+ require 'asana-god-contact/stats'
2
+ require 'asana-god-contact/config'
3
+ require 'asana-god-contact/logger'
4
+ require 'net/https'
5
+ require 'json'
6
+ require 'god'
7
+
8
+ module AsanaGodContact
9
+ class Connector
10
+ def initialize(options)
11
+ AsanaGodContact::Config::PARAMS.each do |param|
12
+ raise "Required option #{param} not set." unless options[param]
13
+ end
14
+
15
+ @options = options
16
+ @uri = URI.parse(AsanaGodContact::Config::ASANA_URL)
17
+ end
18
+
19
+ def create_task
20
+ http = Net::HTTP.new(@uri.host, @uri.port)
21
+ http.use_ssl = true
22
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
23
+ res = http.start { |http| http.request(request_params) }
24
+
25
+ AsanaGodContact::Logger.responce_message JSON.parse(res.body)
26
+ end
27
+
28
+ private
29
+ def request_params
30
+ header = {"Content-Type" => "application/json"}
31
+ req = Net::HTTP::Post.new(@uri.path, header)
32
+ req.basic_auth(@options[:api_key], '')
33
+ req.body = request_body
34
+ req
35
+ end
36
+
37
+ def request_body
38
+ {
39
+ "data" => {
40
+ "workspace" => @options[:workspace_id],
41
+ "name" => @options[:message],
42
+ "assignee" => @options[:assignee],
43
+ "projects" => @options[:projects],
44
+ "folowers" => @options[:folowers],
45
+ "notes" => AsanaGodContact::Stats.list
46
+ }
47
+ }.to_json()
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,7 @@
1
+ module AsanaGodContact
2
+ module Config
3
+ API_VERSION = '1.0'
4
+ ASANA_URL = "https://app.asana.com/api/#{API_VERSION}/tasks"
5
+ PARAMS = [:api_key, :workspace_id ,:assignee, :projects, :folowers]
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module AsanaGodContact
2
+ class Logger
3
+ def self.responce_message(body)
4
+ if body['errors'] then
5
+ applog(nil, :error, "Asana returned an error: #{body['errors'][0]['message']}")
6
+ else
7
+ applog(nil, :info, "Created Asana task with id: #{body['data']['id']} for user #{body['data']['assignee']['name']}")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'sys/proctable'
2
+ include Sys
3
+
4
+ module AsanaGodContact
5
+ class Stats
6
+ def self.list
7
+ ProcTable.ps{ |p|
8
+ (@processes ||= "") << "id: #{p.pid} command: #{p.comm} \ncmdline: #{p.cmdline}\n\n"
9
+ }
10
+ @processes.to_s
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module AsanaGodContact
2
+ VERSION = "0.0.4"
3
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asana-god-contact
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Roman Rott
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: god
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sys-proctable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.7'
111
+ description: Allows to send notifications to Asana
112
+ email:
113
+ - roman.rott@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - asana-god-contact.gemspec
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/asana-god-contact.rb
128
+ - lib/asana-god-contact/asana_connector.rb
129
+ - lib/asana-god-contact/config.rb
130
+ - lib/asana-god-contact/logger.rb
131
+ - lib/asana-god-contact/stats.rb
132
+ - lib/asana-god-contact/version.rb
133
+ homepage: https://github.com/rrott/asana-god-contact
134
+ licenses:
135
+ - GPL
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.4.7
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: A God::Contacts class for sending notifications to Asana
157
+ test_files: []
158
+ has_rdoc: