epoch_api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzQyMTg2MmM5NjMwOWRkYTAwYzFiN2VlZjg1MjRiNTk1MGZiY2Y1Mw==
5
+ data.tar.gz: !binary |-
6
+ NWRjY2FiMzY0MzRlZGQyZDE2ZDkzZTQ1NDA5YmJkZjUxYmQ3ZDJkNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZGRlODQwODRjNTAyZDkzNDhjZDQxZGY3OGU0YWQ3M2JkZTczNWY2ZDRlZWIy
10
+ ZTY1ODdiMzdmOTE4ODJlMzJhZjcwZDBiODk1ZTk5OGQ4MzVlMjQ5NGNhOWI0
11
+ NmI2MDY2YmM4MmRiZjFjZTNiYWE4MWJkYThiNTRjYzgwOTQ1YmU=
12
+ data.tar.gz: !binary |-
13
+ Y2U4YWM2YzA0NzEyNmE3MjA1OGM1MzI2OGIxNjYxZGUxMGQyNjQ4MzZlZmQ0
14
+ YzAyZmFmYzExOGEwODc5YWEzNjc1ZTkzYzBlMTI1ZjMxODQ4MmY4YjE5MmFl
15
+ MTEzYjYyNjM0M2M2YzA4OWE5ZDUxMzg2YTQ4ZmMyYTQyMDVkYjg=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hipchat.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Monsterbox Productions
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ epoch_api
2
+ ========
3
+
4
+ Ruby library to interact with 3poch
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new do |t|
5
+ t.pattern = 'spec/**/*_spec.rb'
6
+ t.rspec_opts = '-c -fd'
7
+ end
8
+
9
+ task default: :spec
10
+
11
+ require 'rdoc/task'
12
+ Rake::RDocTask.new do |rdoc|
13
+ version = EpochApi::VERSION
14
+
15
+ rdoc.rdoc_dir = 'rdoc'
16
+ rdoc.title = "epoch_api #{version}"
17
+ rdoc.rdoc_files.include 'README*'
18
+ rdoc.rdoc_files.include 'lib/**/*.rb'
19
+ end
data/epoch_api.gemspec ADDED
@@ -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 'epoch_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'epoch_api'
8
+ spec.version = EpochApi::VERSION
9
+ spec.authors = ['Monsterbox Productions']
10
+ spec.email = ['info@monsterboxpro.com']
11
+ spec.description = %q{Ruby library to interact with 3poch}
12
+ spec.summary = %q{Ruby library to interact with 3poch}
13
+ spec.homepage = 'https://github.com/omenking/epoch'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'httparty'
22
+
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'rr'
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'webmock'
28
+ spec.add_development_dependency 'rdoc', '> 2.4.2'
29
+ end
@@ -0,0 +1,113 @@
1
+ require 'epoch_api'
2
+
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+ set :epoch_send_notification, false
5
+ set :epoch_with_migrations, ''
6
+
7
+ namespace :epoch do
8
+ task :trigger_notification do
9
+ set :epoch_send_notification, true if !dry_run
10
+ end
11
+
12
+ task :configure_for_migrations do
13
+ set :epoch_with_migrations, ' (with migrations)'
14
+ end
15
+
16
+ task :notify_deploy_started do
17
+ return unless epoch_send_notification
18
+ environment_string = env
19
+ environment_string = "#{stage} (#{env})" if self.respond_to?(:stage)
20
+ location = "#{deployment_name} to #{environment_string}"
21
+
22
+ on_rollback do
23
+ send_options.merge! color: failed_message_color
24
+ send "#{human} cancelled deployment of #{location}.", send_options
25
+ end
26
+
27
+ send "#{human} is deploying #{location}#{fetch(:epoch_with_migrations, '')}.", send_options
28
+ end
29
+
30
+ task :notify_deploy_finished do
31
+ return unless epoch_send_notification
32
+ send_options.merge! color: success_message_color
33
+
34
+ environment_string = env
35
+ environment_string = "#{stage} (#{env})" if self.respond_to?(:stage)
36
+ location = "#{deployment_name} to #{environment_string}"
37
+
38
+ send "#{human} finished deploying #{location}#{fetch(:epoch_with_migrations, '')}.", send_options)
39
+ end
40
+
41
+ def send_options
42
+ return @send_options if defined?(@send_options)
43
+ @send_options = {}
44
+ @send_options.merge! notify: message_notification
45
+ @send_options.merge! color: message_color
46
+ @send_options
47
+ end
48
+
49
+ def send message, options
50
+ if fetch(:epoch_client, nil).nil?
51
+ set :epoch_client, EpochApi::Client.new epoch_token
52
+ end
53
+
54
+ begin
55
+ epoch_client.message epoch_room_token, deploy_user, message, options
56
+ rescue => e
57
+ puts e.message
58
+ puts e.backtrace
59
+ end
60
+ end
61
+
62
+ def deployment_name
63
+ if fetch(:branch, nil)
64
+ name = "#{application}/#{branch}"
65
+ name += " (revision #{real_revision[0..7]})" if real_revision
66
+ name
67
+ else
68
+ application
69
+ end
70
+ end
71
+
72
+ def message_color
73
+ fetch :epoch_color, nil
74
+ end
75
+
76
+ def success_message_color
77
+ fetch :epoch_success_color, 'green'
78
+ end
79
+
80
+ def failed_message_color
81
+ fetch :epoch_failed_color, 'red'
82
+ end
83
+
84
+ def message_notification
85
+ fetch :epoch_announce, false
86
+ end
87
+
88
+ def deploy_user
89
+ fetch :epoch_deploy_user, 'Deploy'
90
+ end
91
+
92
+ def human
93
+ user = ENV['epoch_USER']
94
+ unless user
95
+ user = 'Someone'
96
+ if (user = %x{git config user.name}.strip) != "" then user
97
+ elsif (user = ENV['USER']) != "" then user
98
+ fetch :epoch_human, user
99
+ end
100
+ end
101
+ end
102
+
103
+ def env
104
+ fetch :epoch_env, fetch(:rack_env, fetch(:rails_env, "production"))
105
+ end
106
+ end
107
+
108
+ before 'deploy' , 'epoch:trigger_notification'
109
+ before 'deploy:migrations' , 'epoch:trigger_notification' , 'epoch:configure_for_migrations'
110
+ before 'deploy:update_code', 'epoch:notify_deploy_started'
111
+ after 'deploy' , 'epoch:notify_deploy_finished'
112
+ after 'deploy:migrations' , 'epoch:notify_deploy_finished'
113
+ end
@@ -0,0 +1,3 @@
1
+ module EpochApi
2
+ VERSION = '0.1.0'
3
+ end
data/lib/epoch_api.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'httparty'
2
+ require 'ostruct'
3
+ require 'epoch_api/version'
4
+
5
+ module EpochApi
6
+ class UnknownRoom < StandardError; end
7
+ class Unauthorized < StandardError; end
8
+ class UnknownResponseCode < StandardError; end
9
+ class UsernameTooLong < StandardError; end
10
+
11
+ class Client
12
+ include HTTParty
13
+
14
+ base_uri 'https://3poch.com/api/v1/rooms'
15
+ format :json
16
+
17
+ def initialize token, options={}
18
+ @token = token
19
+ self
20
+ end
21
+
22
+ def message room_token, from, message, options = {color: 'yellow', notify: false}
23
+ err_msg = "Username #{from} is `#{from.length} characters long. Limit is 15'"
24
+ raise UsernameTooLong, err_msg if from.length > 15
25
+
26
+ response = self.class.put "/#{room_id}/message",
27
+ query: { auth_token: @token },
28
+ body: {
29
+ from: from,
30
+ message: message,
31
+ color: options[:color],
32
+ notify: options[:notify] ? 1 : 0 }
33
+
34
+ _response response
35
+ end
36
+
37
+ def topic new_topic, options = {from: 'API'}
38
+
39
+ response = self.class.put "/#{room_id}/topic",
40
+ query: { auth_token: @token },
41
+ body: {
42
+ from: options[:from],
43
+ topic: new_topic}
44
+
45
+ _response response
46
+ end
47
+
48
+ def _response response
49
+ case response.code
50
+ when 200 then response.body
51
+ when 404 then raise UnknownRoom , "Unknown room: `#{room_id}'"
52
+ when 401 then raise Unauthorized , "Access denied to room `#{room_id}'"
53
+ else; raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'"
54
+ end
55
+ end
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: epoch_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Monsterbox Productions
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
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.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rdoc
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>'
102
+ - !ruby/object:Gem::Version
103
+ version: 2.4.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>'
109
+ - !ruby/object:Gem::Version
110
+ version: 2.4.2
111
+ description: Ruby library to interact with 3poch
112
+ email:
113
+ - info@monsterboxpro.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - epoch_api.gemspec
124
+ - lib/epoch_api.rb
125
+ - lib/epoch_api/capistrano.rb
126
+ - lib/epoch_api/version.rb
127
+ homepage: https://github.com/omenking/epoch
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.1.2
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Ruby library to interact with 3poch
151
+ test_files: []
152
+ has_rdoc: