chawk_remote 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0cb494c02327945215f18567a20853585b9a2adb
4
+ data.tar.gz: 566a4eaaf1f89314c9b9c22ae54964378e6c5016
5
+ SHA512:
6
+ metadata.gz: ae4bf4e698819152eaa876409ff03cc2bbe39a50b895191e085ceb33cfc7a70b0daaec73e18523851ed6d50bb14f6d4cb5c9ffb4aa261bcb435a479a898aa9a4
7
+ data.tar.gz: 18491316d90fd989a8eb68c2a61ea2c7c6232ee689de6e38b754fa7a938d2eb6d662f7d2d84311d636bbdc9afde10a78d74c13420eb983ef09005b7c959a2ccb
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.pryrc ADDED
@@ -0,0 +1,8 @@
1
+ $:.unshift('lib')
2
+
3
+ require 'hirb'
4
+ require 'chawk_remote'
5
+
6
+
7
+ Hirb.enable
8
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chawk_remote.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Scott Russell
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # ChawkRemote
2
+
3
+ This is a remote client library for the Chawk time series storage engine. It also includes a command-line client, chawk_remote
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'chawk_remote'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install chawk_remote
18
+
19
+ ## Usage
20
+
21
+ Shortened response commands
22
+ chawk_remote -h http://localhost:3000 -n 1 -x client_api_id -a api_key clear
23
+ {"addr"=>"1", "prepared_at"=>"2014-03-24T08:39:48-04:00", "key_expires"=>"2014-04-06T00:43:09.102Z"}
24
+
25
+ Standard response commands
26
+ chawk_remote -h http://localhost:3000 -n 1 -x client_api_id -a api_key add 1,2,3
27
+ chawk_remote -h http://localhost:3000 -n 1 -x client_api_id -a api_key increment 10
28
+ chawk_remote -h http://localhost:3000 -n 1 -x client_api_id -a api_key decrement 10
29
+
30
+ {"addr"=>"1",
31
+ "prepared_at"=>"2014-03-24T08:34:26-04:00",
32
+ "key_expires"=>"2014-04-06T00:43:09.102Z",
33
+ "last"=>{
34
+ "v"=>2,
35
+ "t"=>1395664466.422626,
36
+ "m"=>{"source"=>"chawk_remote/chawkolate_api_v_0.2.0"}
37
+ },
38
+ "max"=>3,
39
+ "min"=>1,
40
+ "length"=>4
41
+ }
42
+
43
+ Full response commands
44
+ chawk_remote -h http://localhost:3000 -n 1 -x client_api_id -a api_key last
45
+
46
+ {"addr"=>"1",
47
+ "prepared_at"=>"2014-03-24T08:34:26-04:00",
48
+ "key_expires"=>"2014-04-06T00:43:09.102Z",
49
+ "data"=>[
50
+ {"v"=>1, "t"=>1395664893.472671, "m"=>{"source"=>"chawk_remote/chawkolate_api_v_0.2.0"}, "i"=>1},
51
+ {"v"=>2, "t"=>1395664893.472671, "m"=>{"source"=>"chawk_remote/chawkolate_api_v_0.2.0"}, "i"=>2},
52
+ {"v"=>3, "t"=>1395664893.472671, "m"=>{"source"=>"chawk_remote/chawkolate_api_v_0.2.0"}, "i"=>3}],
53
+ "last"=>{
54
+ "v"=>2,
55
+ "t"=>1395664466.422626,
56
+ "m"=>{"source"=>"chawk_remote/chawkolate_api_v_0.2.0"}
57
+ },
58
+ "max"=>3,
59
+ "min"=>1,
60
+ "length"=>4
61
+ }
62
+
63
+ ## Contributing
64
+
65
+ 1. Fork it ( http://github.com/<my-github-username>/chawk_remote/fork )
66
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
67
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
68
+ 4. Push to the branch (`git push origin my-new-feature`)
69
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/chawk_remote ADDED
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+ require 'chawk_remote'
3
+ require 'optparse'
4
+ require 'yaml'
5
+ require 'pp'
6
+
7
+ options = {}
8
+
9
+ opt = OptionParser.new do |opts|
10
+ opts.banner = "Usage: chawk [options] command [data]"
11
+
12
+ opts.on("-c", "--config file", "Use config file (options will override)") do |config|
13
+ options = YAML.load_file(config)
14
+ end
15
+
16
+ opts.on("-h", "--host host host", "Set host (http://foo:500)") do |host|
17
+ options[:host] = host
18
+ end
19
+
20
+ opts.on("-x", "--client_api_id id", "Chawk client ID") do |id|
21
+ options[:api_client] = id
22
+ end
23
+
24
+ opts.on("-a", "--client_api_key key", "Chawk client ID") do |key|
25
+ options[:api_key] = key
26
+ end
27
+
28
+ opts.on("-n", "--series_address node", "Chawk series address") do |node|
29
+ options[:node] = node
30
+ end
31
+
32
+ end
33
+
34
+ opt.parse!(ARGV)
35
+
36
+ unless options[:host]
37
+ puts "Host is missing"
38
+ exit 1
39
+ end
40
+ unless options[:node]
41
+ puts "Node is missing"
42
+ exit 1
43
+ end
44
+
45
+ unless options[:api_client]
46
+ puts "Client Api is missing"
47
+ exit 1
48
+ end
49
+
50
+ unless options[:api_key]
51
+ puts "Api Key is missing"
52
+ exit 1
53
+ end
54
+
55
+ case ARGV[0]
56
+
57
+ when "clear"
58
+ x = ChawkRemote::Addr.new(options[:host],options[:node],options[:api_client],options[:api_key])
59
+ puts x.clear
60
+
61
+ when "add"
62
+ points = ARGV[1..1].flatten.join().split(",")
63
+ x = ChawkRemote::Addr.new(options[:host],options[:node],options[:api_client],options[:api_key])
64
+ puts x.add_points points
65
+
66
+ when "increment"
67
+ x = ChawkRemote::Addr.new(options[:host],options[:node],options[:api_client],options[:api_key])
68
+ puts x.increment ARGV[1]
69
+
70
+ when "decrement"
71
+ x = ChawkRemote::Addr.new(options[:host],options[:node],options[:api_client],options[:api_key])
72
+ puts x.decrement ARGV[1]
73
+
74
+ when "last"
75
+ x = ChawkRemote::Addr.new(options[:host],options[:node],options[:api_client],options[:api_key])
76
+ puts x.last 100
77
+ else
78
+ puts "Command #{ARGV[0]} unknown."
79
+ end
@@ -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 'chawk_remote/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chawk_remote"
8
+ spec.version = ChawkRemote::VERSION
9
+ spec.authors = ["Scott Russell"]
10
+ spec.email = ["queuetue@gmail.com"]
11
+ spec.summary = %q{A ruby wrapper for the chawk REST api.}
12
+ spec.description = %q{A ruby wrapper for the chawk REST api.}
13
+ spec.homepage = ""
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 'multipart-post', '~> 1.1'
22
+ spec.add_dependency 'json'
23
+ spec.add_dependency 'httparty'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.5"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency 'rspec', '~> 2.6'
28
+ spec.add_development_dependency 'webmock'
29
+ end
@@ -0,0 +1,57 @@
1
+ require "chawk_remote/version"
2
+ require "httparty"
3
+
4
+ module ChawkRemote
5
+ class Addr
6
+ include HTTParty
7
+ attr_accessor :host, :series_key, :client_id, :api_key
8
+
9
+ def initialize(host, series_key, client_id, api_key)
10
+ @host = host
11
+ @client_id = client_id
12
+ @api_key = api_key
13
+ @series_key = series_key
14
+
15
+ #puts "#{@host} - #{@client_id} - #{@api_key} #{series_key}"
16
+
17
+ end
18
+
19
+ def clear
20
+ r = HTTParty.put "#{@host}/api/v1/nodes/#{@series_key}/clear", :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""}
21
+ end
22
+
23
+ def add_points(points)
24
+ r = HTTParty.post "#{@host}/api/v1/nodes/#{@series_key}/add_points",
25
+ :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""},
26
+ :body => {"payload" => "{\"data\":[#{points.join(',')}]}", :meta => "{\"source\":\"chawk_remote\"}"}
27
+ end
28
+
29
+ def increment(count)
30
+ r = HTTParty.put "#{@host}/api/v1/nodes/#{@series_key}/increment",
31
+ :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""},
32
+ :body => {"payload" => "{\"data\":#{count}}", :meta => "{\"source\":\"chawk_remote\"}"}
33
+ end
34
+
35
+ def decrement(count)
36
+ r = HTTParty.put "#{@host}/api/v1/nodes/#{@series_key}/decrement",
37
+ :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""},
38
+ :body => {"payload" => "{\"data\":#{count}}", :meta => "{\"source\":\"chawk_remote\"}"}
39
+ end
40
+
41
+ def last(length)
42
+ r = HTTParty.get "#{@host}/api/v1/nodes/#{@series_key}/last",
43
+ :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""}
44
+ end
45
+
46
+ def range(from, to)
47
+ r = HTTParty.get "#{@host}/api/v1/nodes/#{@series_key}/range?from=#{from}&to=#{to}",
48
+ :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""}
49
+ end
50
+
51
+ def since (from)
52
+ r = HTTParty.get "#{@host}/api/v1/nodes/#{@series_key}/since?from=#{from}",
53
+ :headers=>{"Authorization"=>"Token token=\"#{@client_id}/#{@api_key}\""}
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module ChawkRemote
2
+ VERSION = "0.2.0"
3
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chawk_remote
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Scott Russell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multipart-post
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
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: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A ruby wrapper for the chawk REST api.
112
+ email:
113
+ - queuetue@gmail.com
114
+ executables:
115
+ - chawk_remote
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".pryrc"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/chawk_remote
126
+ - chawk_remote.gemspec
127
+ - lib/chawk_remote.rb
128
+ - lib/chawk_remote/version.rb
129
+ homepage: ''
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.2.2
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: A ruby wrapper for the chawk REST api.
153
+ test_files: []