codegears 0.0.1.pre → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/codegears.gemspec CHANGED
@@ -1,8 +1,7 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib/', __FILE__)
3
- $:.unshift lib unless $:.include?(lib)
2
+ $:.unshift File.expand_path("../lib/", __FILE__)
4
3
 
5
- require "cg/version"
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/Semjonow/codegears"
13
+ gem.homepage = "https://github.com/code-gears/codegears"
15
14
  gem.license = "MIT"
16
- gem.executables = ["cg"]
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/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,83 @@
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)
48
+ instance = self.instance
49
+
50
+ instance.channel = channel
51
+ instance.message = yield
52
+
53
+ instance.response = CG::API.push_message_request(instance.channel, instance.message)
54
+ end
55
+
56
+ def self.push(channel, message)
57
+ instance = self.instance
58
+
59
+ instance.channel = instance.perform(channel)
60
+ instance.message = message
61
+
62
+ instance.response = CG::API.push_message_request(instance.channel, instance.message)
63
+ end
64
+
65
+ def self.stats
66
+ instance = self.instance
67
+
68
+ CG::API.show_app_request(instance.id, instance.secret_id, instance.secret_token)
69
+ end
70
+
71
+ def channel=(ch)
72
+ @channel = perform(ch)
73
+ end
74
+
75
+ def push
76
+ instance.response = CG::API.push_message_request(channel, message)
77
+ end
78
+
79
+ def perform(channel)
80
+ channel[0] == "/" ? channel : "/#{channel}"
81
+ end
82
+ end
83
+ end
data/lib/cg/cli.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "rubygems"
2
+ require "cg/command"
3
+
4
+ module CG
5
+ class CLI
6
+ def self.start(*args)
7
+ CG::Command.new(*args)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ require "cg/api"
2
+ require "colorize"
3
+
4
+ module Command
5
+ class App
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
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ require "cg/version"
2
+
3
+ module Command
4
+ class Version
5
+ def self.main(*args)
6
+ puts CG::VERSION
7
+ end
8
+ end
9
+ end
data/lib/cg/command.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "cg/version"
2
+
3
+ module CG
4
+ class Command
5
+ def initialize(*args)
6
+ Dir[File.join(File.dirname(__FILE__), "command", "*.rb")].each do |file|
7
+ require file
8
+ end
9
+
10
+ namespace = args.shift.capitalize rescue nil
11
+ namespace = Kernel.const_get("Command").const_get(namespace) rescue nil
12
+ task = args.shift.downcase rescue nil
13
+
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
23
+ end
24
+ end
25
+ end
data/lib/cg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CG
2
- VERSION = "0.0.1.pre"
2
+ VERSION = "0.0.1"
3
3
  end
data/lib/cg.rb CHANGED
@@ -1,4 +1,9 @@
1
+ require "rails"
1
2
  require "cg/version"
3
+ require "cg/app"
2
4
 
3
5
  module CG
6
+ class Engine < Rails::Engine
7
+
8
+ end
4
9
  end
@@ -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
@@ -0,0 +1,7 @@
1
+ require "cg"
2
+
3
+ CG::APP.configure do |instance|
4
+ instance.id = "<%= @id %>"
5
+ instance.secret_id = "<%= @secret_id %>"
6
+ instance.secret_token = "<%= @secret_token %>"
7
+ 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.1.pre
5
- prerelease: 6
4
+ version: 0.0.1
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-04-28 00:00:00.000000000 Z
12
+ date: 2013-05-04 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
@@ -72,12 +88,20 @@ files:
72
88
  - LICENSE
73
89
  - README.md
74
90
  - Rakefile
91
+ - bin/cg
75
92
  - codegears.gemspec
76
93
  - lib/cg.rb
94
+ - lib/cg/api.rb
95
+ - lib/cg/app.rb
96
+ - lib/cg/cli.rb
97
+ - lib/cg/command.rb
98
+ - lib/cg/command/app.rb
99
+ - lib/cg/command/version.rb
77
100
  - lib/cg/pusher.rb
78
101
  - lib/cg/version.rb
79
- - bin/cg
80
- homepage: https://github.com/Semjonow/codegears
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
81
105
  licenses:
82
106
  - MIT
83
107
  post_install_message:
@@ -93,9 +117,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
117
  required_rubygems_version: !ruby/object:Gem::Requirement
94
118
  none: false
95
119
  requirements:
96
- - - ! '>'
120
+ - - ! '>='
97
121
  - !ruby/object:Gem::Version
98
- version: 1.3.1
122
+ version: '0'
99
123
  requirements: []
100
124
  rubyforge_project:
101
125
  rubygems_version: 1.8.23