codegears 0.0.2.pre → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cg +1 -5
- data/codegears.gemspec +5 -5
- data/lib/cg.rb +5 -0
- data/lib/cg/api.rb +32 -0
- data/lib/cg/app.rb +74 -0
- data/lib/cg/command.rb +11 -1
- data/lib/cg/command/app.rb +30 -2
- data/lib/cg/command/version.rb +9 -0
- data/lib/cg/version.rb +1 -1
- data/lib/generators/cg/install/install_generator.rb +32 -0
- data/lib/generators/cg/install/templates/config.rb.template +7 -0
- metadata +27 -6
data/bin/cg
CHANGED
data/codegears.gemspec
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
3
|
-
$:.unshift lib unless $:.include?(lib)
|
2
|
+
$:.unshift File.expand_path("../lib/", __FILE__)
|
4
3
|
|
5
|
-
require "cg
|
4
|
+
require "cg"
|
6
5
|
|
7
6
|
Gem::Specification.new do |gem|
|
8
7
|
gem.name = "codegears"
|
@@ -11,9 +10,9 @@ Gem::Specification.new do |gem|
|
|
11
10
|
gem.email = ["js@codegears.co"]
|
12
11
|
gem.description = %q{Client library and CLI to manage apps on CodeGears}
|
13
12
|
gem.summary = %q{Client library and command-line tool to manage apps on CodeGears}
|
14
|
-
gem.homepage = "https://github.com/
|
13
|
+
gem.homepage = "https://github.com/code-gears/codegears"
|
15
14
|
gem.license = "MIT"
|
16
|
-
gem.executables
|
15
|
+
gem.executables << "cg"
|
17
16
|
gem.default_executable = "cg"
|
18
17
|
|
19
18
|
gem.files = %x{ git ls-files }.split("\n").select { |d| d =~ %r{^(LICENSE|README|bin/|lib/|)} }
|
@@ -21,4 +20,5 @@ Gem::Specification.new do |gem|
|
|
21
20
|
gem.add_dependency "rails"
|
22
21
|
gem.add_dependency "jquery-rails"
|
23
22
|
gem.add_dependency "httparty"
|
23
|
+
gem.add_dependency "colorize"
|
24
24
|
end
|
data/lib/cg.rb
CHANGED
data/lib/cg/api.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
module CG
|
4
|
+
class API
|
5
|
+
include HTTParty
|
6
|
+
ROOT_URL = "http://api.codegears.co"
|
7
|
+
PUSHER_URL = "#{ROOT_URL}:9292/stream"
|
8
|
+
|
9
|
+
def self.create_app_request(email)
|
10
|
+
JSON.parse(self.post("#{ROOT_URL}/apps", :body => { :application => { :email => email } }).body)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.show_app_request(id, secret_id = nil, secret_token = nil)
|
14
|
+
JSON.parse(self.get("#{ROOT_URL}/apps/#{id}?#{self.attach_auth(secret_id, secret_token)}").body)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.push_message_request(channel, message)
|
18
|
+
message = { :channel => channel,
|
19
|
+
:message => message,
|
20
|
+
:ext => { :secret_id => CG::APP.secret_id, :secret_token => CG::APP.secret_token } }.to_json
|
21
|
+
JSON.parse(Net::HTTP.post_form(URI.parse(PUSHER_URL), :message => message).body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.attach_auth(secret_id, secret_token)
|
25
|
+
if secret_id && secret_token
|
26
|
+
"secret_id=#{secret_id}&secret_token=#{secret_token}"
|
27
|
+
else
|
28
|
+
""
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/cg/app.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "singleton"
|
2
|
+
require "cg/api"
|
3
|
+
|
4
|
+
module CG
|
5
|
+
class APP
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
attr_accessor :secret_id, :secret_token, :id, :channel, :message, :sent, :response
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield(self.instance)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.id
|
15
|
+
self.instance.id
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.secret_id
|
19
|
+
self.instance.secret_id
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.secret_token
|
23
|
+
self.instance.secret_token
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.init_message
|
27
|
+
yield(self.instance)
|
28
|
+
self.instance
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.message
|
32
|
+
self.instance.message
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.channel
|
36
|
+
self.instance.channel
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.sent?
|
40
|
+
!!self.instance.sent
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.response
|
44
|
+
self.instance.response
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.push(channel, message = nil)
|
48
|
+
instance = self.instance
|
49
|
+
|
50
|
+
instance.channel = instance.perform(channel)
|
51
|
+
instance.message = message || yield
|
52
|
+
|
53
|
+
instance.response = CG::API.push_message_request(instance.channel, instance.message)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.stats
|
57
|
+
instance = self.instance
|
58
|
+
|
59
|
+
CG::API.show_app_request(instance.id, instance.secret_id, instance.secret_token)
|
60
|
+
end
|
61
|
+
|
62
|
+
def channel=(ch)
|
63
|
+
@channel = perform(ch)
|
64
|
+
end
|
65
|
+
|
66
|
+
def push
|
67
|
+
instance.response = CG::API.push_message_request(channel, message)
|
68
|
+
end
|
69
|
+
|
70
|
+
def perform(channel)
|
71
|
+
channel[0] == "/" ? channel : "/#{channel}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/cg/command.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "cg/version"
|
2
|
+
|
1
3
|
module CG
|
2
4
|
class Command
|
3
5
|
def initialize(*args)
|
@@ -9,7 +11,15 @@ module CG
|
|
9
11
|
namespace = Kernel.const_get("Command").const_get(namespace) rescue nil
|
10
12
|
task = args.shift.downcase rescue nil
|
11
13
|
|
12
|
-
namespace
|
14
|
+
if namespace
|
15
|
+
if task
|
16
|
+
namespace.send(task, *args)
|
17
|
+
else
|
18
|
+
namespace.send("main", *args)
|
19
|
+
end
|
20
|
+
else
|
21
|
+
puts CG::VERSION
|
22
|
+
end
|
13
23
|
end
|
14
24
|
end
|
15
25
|
end
|
data/lib/cg/command/app.rb
CHANGED
@@ -1,7 +1,35 @@
|
|
1
|
+
require "cg/api"
|
2
|
+
require "colorize"
|
3
|
+
|
1
4
|
module Command
|
2
5
|
class App
|
3
|
-
def self.create
|
4
|
-
|
6
|
+
def self.create(email = "")
|
7
|
+
response = CG::API.create_app_request(email)
|
8
|
+
if response["success"] == false
|
9
|
+
response["errors"].each do |k,v|
|
10
|
+
puts "#{k.capitalize} #{v.first}\n".red
|
11
|
+
end
|
12
|
+
else
|
13
|
+
puts "Application successfully created.".green
|
14
|
+
puts "Add the following lines to the file config/initializers/codegears.rb:\n".green
|
15
|
+
puts "require \"cg\"\n".green
|
16
|
+
puts "CG::App.configure do |instance|".green
|
17
|
+
puts " instance.id = \"#{response['id']}\"".green
|
18
|
+
puts " instance.secret_id = \"#{response['secret_id']}\"".green
|
19
|
+
puts " instance.secret_token = \"#{response['secret_token']}\"\n".green
|
20
|
+
puts "end\n".green
|
21
|
+
puts "And restart application to start using the CodeGears platform.".green
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.status(id = "")
|
26
|
+
response = CG::API.show_app_request(id)
|
27
|
+
if response["success"] == false
|
28
|
+
puts "Application not found".red
|
29
|
+
else
|
30
|
+
status = response["active"]
|
31
|
+
puts "Active: #{status}".send(status ? :green : :red)
|
32
|
+
end
|
5
33
|
end
|
6
34
|
end
|
7
35
|
end
|
data/lib/cg/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "cg/api"
|
2
|
+
require "colorize"
|
3
|
+
|
4
|
+
module Cg
|
5
|
+
module Generators
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
desc "This generator installs CodeGears configuration in config/initializers/codegears.rb"
|
9
|
+
|
10
|
+
argument :email, :type => :string, :default => ""
|
11
|
+
|
12
|
+
def create_config_file
|
13
|
+
init_settings
|
14
|
+
template "config.rb.template", "config/initializers/codegears.rb"
|
15
|
+
puts "Restart application to start using the CodeGears platform.".green
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def init_settings
|
21
|
+
unless email.blank?
|
22
|
+
response = CG::API.create_app_request(email)
|
23
|
+
unless response["success"] == false
|
24
|
+
@id = response['id']
|
25
|
+
@secret_id = response['secret_id']
|
26
|
+
@secret_token = response['secret_token']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codegears
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Juri Semjonov
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: colorize
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
62
78
|
description: Client library and CLI to manage apps on CodeGears
|
63
79
|
email:
|
64
80
|
- js@codegears.co
|
@@ -75,12 +91,17 @@ files:
|
|
75
91
|
- bin/cg
|
76
92
|
- codegears.gemspec
|
77
93
|
- lib/cg.rb
|
94
|
+
- lib/cg/api.rb
|
95
|
+
- lib/cg/app.rb
|
78
96
|
- lib/cg/cli.rb
|
79
97
|
- lib/cg/command.rb
|
80
98
|
- lib/cg/command/app.rb
|
99
|
+
- lib/cg/command/version.rb
|
81
100
|
- lib/cg/pusher.rb
|
82
101
|
- lib/cg/version.rb
|
83
|
-
|
102
|
+
- lib/generators/cg/install/install_generator.rb
|
103
|
+
- lib/generators/cg/install/templates/config.rb.template
|
104
|
+
homepage: https://github.com/code-gears/codegears
|
84
105
|
licenses:
|
85
106
|
- MIT
|
86
107
|
post_install_message:
|
@@ -96,9 +117,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
118
|
none: false
|
98
119
|
requirements:
|
99
|
-
- - ! '
|
120
|
+
- - ! '>='
|
100
121
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
122
|
+
version: '0'
|
102
123
|
requirements: []
|
103
124
|
rubyforge_project:
|
104
125
|
rubygems_version: 1.8.23
|