flydata 0.0.1.nc1

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.
data/.gitignore ADDED
@@ -0,0 +1,49 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rest-client"
4
+ gem "i18n"
5
+ gem "activesupport"
6
+ gem "json"
7
+ gem "highline"
8
+ gem "fluentd"
9
+
10
+ group :development do
11
+ gem "bundler"
12
+ gem "jeweler"
13
+ gem "rspec"
14
+ gem "autotest"
15
+ gem "autotest-standalone"
16
+ gem "autotest-notification"
17
+ gem "ZenTest"
18
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ ZenTest (4.8.2)
5
+ activesupport (3.2.8)
6
+ i18n (~> 0.6)
7
+ multi_json (~> 1.0)
8
+ autotest (4.4.6)
9
+ ZenTest (>= 4.4.1)
10
+ autotest-notification (2.3.4)
11
+ autotest-standalone (~> 4.5)
12
+ autotest-standalone (4.5.9)
13
+ cool.io (1.1.0)
14
+ iobuffer (>= 1.0.0)
15
+ diff-lcs (1.1.3)
16
+ fluentd (0.10.25)
17
+ cool.io (~> 1.1.0)
18
+ http_parser.rb (~> 0.5.1)
19
+ json (>= 1.4.3)
20
+ msgpack (~> 0.4.4)
21
+ yajl-ruby (~> 1.0)
22
+ git (1.2.5)
23
+ highline (1.6.15)
24
+ http_parser.rb (0.5.3)
25
+ i18n (0.6.1)
26
+ iobuffer (1.1.2)
27
+ jeweler (1.8.4)
28
+ bundler (~> 1.0)
29
+ git (>= 1.2.5)
30
+ rake
31
+ rdoc
32
+ json (1.7.5)
33
+ mime-types (1.19)
34
+ msgpack (0.4.7)
35
+ multi_json (1.3.6)
36
+ rake (0.9.2.2)
37
+ rdoc (3.12)
38
+ json (~> 1.4)
39
+ rest-client (1.6.7)
40
+ mime-types (>= 1.16)
41
+ rspec (2.11.0)
42
+ rspec-core (~> 2.11.0)
43
+ rspec-expectations (~> 2.11.0)
44
+ rspec-mocks (~> 2.11.0)
45
+ rspec-core (2.11.1)
46
+ rspec-expectations (2.11.3)
47
+ diff-lcs (~> 1.1.3)
48
+ rspec-mocks (2.11.3)
49
+ yajl-ruby (1.1.0)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ ZenTest
56
+ activesupport
57
+ autotest
58
+ autotest-notification
59
+ autotest-standalone
60
+ bundler
61
+ fluentd
62
+ highline
63
+ i18n
64
+ jeweler
65
+ json
66
+ rest-client
67
+ rspec
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "flydata"
18
+ gem.homepage = "http://flydata.co/"
19
+ gem.license = "All right reserved."
20
+ gem.summary = %Q{FlyData CLI}
21
+ gem.description = %Q{FlyData Command Line Interface}
22
+ gem.email = "sysadmin@flydata.co"
23
+ gem.authors = ["Koichi Fujikawa"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require "rspec/core/rake_task"
29
+ desc "Run all specs"
30
+ RSpec::Core::RakeTask.new(:spec) do |t|
31
+ t.verbose = true
32
+ end
33
+
34
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1.nc1
data/bin/flydata ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'rubygems'
7
+ require 'flydata'
8
+
9
+ args = ARGV.dup
10
+ ARGV.clear # for 'gets'
11
+ Flydata::Cli.new(args).run
data/flydata.gemspec ADDED
@@ -0,0 +1,106 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "flydata"
8
+ s.version = "0.0.1.nc1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Koichi Fujikawa"]
12
+ s.date = "2012-10-26"
13
+ s.description = "FlyData Command Line Interface"
14
+ s.email = "sysadmin@flydata.co"
15
+ s.executables = ["flydata"]
16
+ s.files = [
17
+ ".gitignore",
18
+ ".rspec",
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "bin/flydata",
24
+ "flydata.gemspec",
25
+ "lib/flydata.rb",
26
+ "lib/flydata/api/base.rb",
27
+ "lib/flydata/api/data_entry.rb",
28
+ "lib/flydata/api/data_port.rb",
29
+ "lib/flydata/api_client.rb",
30
+ "lib/flydata/cli.rb",
31
+ "lib/flydata/command/base.rb",
32
+ "lib/flydata/command/crontab.rb",
33
+ "lib/flydata/command/login.rb",
34
+ "lib/flydata/command/restart.rb",
35
+ "lib/flydata/command/routine.rb",
36
+ "lib/flydata/command/sender.rb",
37
+ "lib/flydata/command/setlogdel.rb",
38
+ "lib/flydata/command/setup.rb",
39
+ "lib/flydata/command/start.rb",
40
+ "lib/flydata/command/stop.rb",
41
+ "lib/flydata/credentials.rb",
42
+ "lib/flydata/cron.rb",
43
+ "lib/flydata/flydata_crontab.sh",
44
+ "lib/flydata/helpers.rb",
45
+ "lib/flydata/log_monitor.rb",
46
+ "lib/flydata/proxy.rb",
47
+ "spec/flydata/api/data_entry_spec.rb",
48
+ "spec/flydata/command/sender_spec.rb",
49
+ "spec/flydata_spec.rb",
50
+ "spec/spec_helper.rb"
51
+ ]
52
+ s.homepage = "http://flydata.co/"
53
+ s.licenses = ["All right reserved."]
54
+ s.require_paths = ["lib"]
55
+ s.rubygems_version = "1.8.23"
56
+ s.summary = "FlyData CLI"
57
+
58
+ if s.respond_to? :specification_version then
59
+ s.specification_version = 3
60
+
61
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
62
+ s.add_runtime_dependency(%q<rest-client>, [">= 0"])
63
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
64
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
65
+ s.add_runtime_dependency(%q<json>, [">= 0"])
66
+ s.add_runtime_dependency(%q<highline>, [">= 0"])
67
+ s.add_runtime_dependency(%q<fluentd>, [">= 0"])
68
+ s.add_development_dependency(%q<bundler>, [">= 0"])
69
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
70
+ s.add_development_dependency(%q<rspec>, [">= 0"])
71
+ s.add_development_dependency(%q<autotest>, [">= 0"])
72
+ s.add_development_dependency(%q<autotest-standalone>, [">= 0"])
73
+ s.add_development_dependency(%q<autotest-notification>, [">= 0"])
74
+ s.add_development_dependency(%q<ZenTest>, [">= 0"])
75
+ else
76
+ s.add_dependency(%q<rest-client>, [">= 0"])
77
+ s.add_dependency(%q<i18n>, [">= 0"])
78
+ s.add_dependency(%q<activesupport>, [">= 0"])
79
+ s.add_dependency(%q<json>, [">= 0"])
80
+ s.add_dependency(%q<highline>, [">= 0"])
81
+ s.add_dependency(%q<fluentd>, [">= 0"])
82
+ s.add_dependency(%q<bundler>, [">= 0"])
83
+ s.add_dependency(%q<jeweler>, [">= 0"])
84
+ s.add_dependency(%q<rspec>, [">= 0"])
85
+ s.add_dependency(%q<autotest>, [">= 0"])
86
+ s.add_dependency(%q<autotest-standalone>, [">= 0"])
87
+ s.add_dependency(%q<autotest-notification>, [">= 0"])
88
+ s.add_dependency(%q<ZenTest>, [">= 0"])
89
+ end
90
+ else
91
+ s.add_dependency(%q<rest-client>, [">= 0"])
92
+ s.add_dependency(%q<i18n>, [">= 0"])
93
+ s.add_dependency(%q<activesupport>, [">= 0"])
94
+ s.add_dependency(%q<json>, [">= 0"])
95
+ s.add_dependency(%q<highline>, [">= 0"])
96
+ s.add_dependency(%q<fluentd>, [">= 0"])
97
+ s.add_dependency(%q<bundler>, [">= 0"])
98
+ s.add_dependency(%q<jeweler>, [">= 0"])
99
+ s.add_dependency(%q<rspec>, [">= 0"])
100
+ s.add_dependency(%q<autotest>, [">= 0"])
101
+ s.add_dependency(%q<autotest-standalone>, [">= 0"])
102
+ s.add_dependency(%q<autotest-notification>, [">= 0"])
103
+ s.add_dependency(%q<ZenTest>, [">= 0"])
104
+ end
105
+ end
106
+
data/lib/flydata.rb ADDED
@@ -0,0 +1,16 @@
1
+ # common
2
+ require 'active_support/core_ext/string'
3
+ require 'active_support/dependencies'
4
+ require 'active_support/time'
5
+ require 'highline/import'
6
+ require 'readline'
7
+ require 'json'
8
+ require 'pp'
9
+
10
+ # require all flydata libs
11
+ lib_dir = File.expand_path(File.dirname(__FILE__))
12
+ ActiveSupport::Dependencies.autoload_paths << lib_dir
13
+
14
+ module Flydata
15
+ HOME_DIR="#{ENV['HOME']}/.flydata"
16
+ end
@@ -0,0 +1,16 @@
1
+ module Flydata
2
+ module Api
3
+ class Base
4
+ def initialize(api_client)
5
+ @client = api_client
6
+ end
7
+ def list(params={})
8
+ @client.get(@url_path)
9
+ end
10
+ def create(params={})
11
+ params.each {|k, v| @url_path.gsub!(/:#{k}/, v.to_s)}
12
+ @client.post(@url_path, @model_name => params)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Flydata
2
+ module Api
3
+ class DataEntry < Base
4
+ def initialize(api_client)
5
+ @model_name = 'data_entry'
6
+ @url_path = "/data_ports/:data_port_id/#{@model_name.pluralize}"
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Flydata
2
+ module Api
3
+ class DataPort < Base
4
+ def initialize(api_client)
5
+ @model_name = 'data_port'
6
+ @url_path = "/#{@model_name.pluralize}"
7
+ super
8
+ end
9
+ def get
10
+ # currently one user has one data port
11
+ self.list.first
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,57 @@
1
+ require 'rest_client'
2
+ require 'singleton'
3
+
4
+ module Flydata
5
+ FLYDATA_API_HOST = ENV['FLYDATA_API_HOST'] || 'flydata.co'
6
+
7
+ class ApiClient
8
+ include Singleton
9
+ attr_reader :response
10
+ attr_accessor :credentials
11
+
12
+ def initialize
13
+ @credentials = Flydata::Credentials.new
14
+ end
15
+
16
+ # row level api
17
+ def post(path, params=nil)
18
+ uri = "http://#{FLYDATA_API_HOST}#{path}"
19
+ resource = RestClient::Resource.new(uri, resource_opts)
20
+ @response = resource.post(params, :accept => :json)
21
+ handle_response response
22
+ end
23
+ def put(path, params=nil)
24
+ uri = "http://#{FLYDATA_API_HOST}#{path}"
25
+ resource = RestClient::Resource.new(uri, resource_opts)
26
+ @response = resource.put(params, :accept => :json)
27
+ handle_response response
28
+ end
29
+ def get(path)
30
+ uri = "http://#{FLYDATA_API_HOST}#{path}"
31
+ resource = RestClient::Resource.new(uri, resource_opts)
32
+ @response = resource.get(:accept => :json)
33
+ handle_response response
34
+ end
35
+
36
+ # high level api
37
+ def method_missing(cls_name, *args, &block)
38
+ method_name = args.shift.to_s
39
+ api_cls = "Flydata::Api::#{cls_name.to_s.camelize}".constantize
40
+ api_cls.new(self)
41
+ end
42
+ def respond_to_missing?(method_name, include_private=false); true end
43
+
44
+ private
45
+ def handle_response(response)
46
+ json_response = JSON.parse(response)
47
+ if json_response.class == Hash and json_response["success"] == false
48
+ err_msg = json_response['errors'] ? json_response['errors'].to_s : "Unkown error."
49
+ raise err_msg
50
+ end
51
+ json_response
52
+ end
53
+ def resource_opts
54
+ {:user => @credentials.user, :password => @credentials.password}
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,41 @@
1
+ module Flydata
2
+ class Cli
3
+ def initialize(args)
4
+ @args = args
5
+ end
6
+
7
+ def run
8
+ begin
9
+ if @args.size > 0
10
+ first_arg = @args.shift
11
+ cmd, sub_cmd = parse_command(first_arg)
12
+ cmd_cls = "Flydata::Command::#{cmd.capitalize}".constantize
13
+ cmd_obj = cmd_cls.new
14
+ sub_cmd ? cmd_obj.send(sub_cmd) : cmd_obj.run
15
+ else
16
+ raise 'no command given'
17
+ end
18
+ rescue => e
19
+ #raise e
20
+ puts "! #{e.to_s}"
21
+ puts
22
+ print_usage
23
+ end
24
+ end
25
+
26
+ private
27
+ def parse_command(cmd)
28
+ cmd.split(':')
29
+ end
30
+ def print_usage
31
+ puts <<-EOM
32
+ Usage: flydata COMMAND
33
+ setup # setup initially
34
+ start # start flydata process
35
+ stop # stop flydata process
36
+ restart # restart flydata process
37
+ setlogdel # show and change log deletion settting
38
+ EOM
39
+ end
40
+ end
41
+ end