dscli 0.0.1

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: be97fdf910c4c1f9dba126aeff2867551efaeee1
4
+ data.tar.gz: c8390e2ca3fce6db88e4761cf51311b0043b86de
5
+ SHA512:
6
+ metadata.gz: 9c74ffe5247d7dde77d097851ff4e1531a70c2632e27506b339507003c5ed4e0c4d4708e7112ae9fee737eab03936c3048bb8a609e3e0964fa1a741cf6d23a6a
7
+ data.tar.gz: a542e3cc952a3335ff4d1c222b90229ecc624854746e0be9250c1fe910ee803f855d6fe7f6859685fb752e02612b4a727b604968ea376e0e55db0ea66d011cc8
data/LICENSE.txt ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2014, Jason Dugdale
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the DataSift nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Dscli
2
+
3
+ DSCLI is a command line wrapper around the DataSift API Client Library for Ruby.
4
+ It was built by the DataSift Support Team to help speed up tasks we found ourselves frequently repeating.
5
+ Version 0.0.1 offers support for only some of the core API functions. Support for the Push and Historics APIs is on it's way.
6
+
7
+ ## Installation
8
+
9
+ This tool was intended for use as a CLI tool only:
10
+
11
+ gem install dscli
12
+
13
+ ## Usage
14
+
15
+ First, call ``` dscli config ``` to enter your DataSift API credentials. This will store your username and API key in a new file called ~/.datasiftcli
16
+ You should then be free to use any of following commands:
17
+
18
+ dscli compile (csdl) # Compile CSDL
19
+ dscli config # Configure your DataSift API credentials
20
+ dscli dpu (hash) # Find the DPU cost of a given stream hash
21
+ dscli help [COMMAND] # Describe available commands or one specific command
22
+ dscli stream (hash) # Stream interactions from a DataSift stream to the command line
23
+ dscli usage [period] # Find your stream and license fee usage
24
+
25
+ ## Contributing
26
+
27
+ Contributions are always appreciated!
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/bin/dscli ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dscli'
4
+
5
+ Dscli::Commands.start(ARGV)
data/lib/dscli/api.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'datasift'
2
+ require 'yajl'
3
+
4
+ module Dscli
5
+ class API
6
+ attr_reader :hash
7
+
8
+ def initialize
9
+ storage = Dscli::Storage.new
10
+ config = storage.get_auth
11
+ @config = {:username => config[:auth][:username], :api_key => config[:auth][:api_key], :enable_ssl => false}
12
+ @datasift = DataSift::Client.new(@config)
13
+ end
14
+
15
+ #
16
+ # Core API endpoints
17
+ # [ Missing /validate /balance ]
18
+
19
+ def compile(csdl)
20
+ response = @datasift.compile csdl
21
+ definition = response[:data]
22
+ definition[:hash]
23
+ end
24
+
25
+ def usage(period)
26
+ response = @datasift.usage period
27
+ usage = response[:data]
28
+ end
29
+
30
+ def dpu(hash)
31
+ response = @datasift.dpu hash
32
+ dpu = response[:data]
33
+ end
34
+
35
+ def stream(hash)
36
+ on_delete = lambda { |stream, m| puts m }
37
+ on_error = lambda { |stream, e| puts 'A serious error has occurred: ' + e.message.to_s }
38
+ on_message = lambda { |message, stream, hash| puts Yajl::Encoder.encode(message) }
39
+ on_connect = lambda { |stream| stream.subscribe(hash, on_message) }
40
+ on_close = lambda { |stream| puts 'closed' }
41
+
42
+ on_datasift_message = lambda do |stream, message, hash|
43
+ puts "DataSift Message #{hash} ==> #{message}"
44
+ end
45
+
46
+ conn = DataSift::new_stream(@config, on_delete, on_error, on_connect, on_close)
47
+ conn.on_datasift_message = on_datasift_message
48
+ conn.stream.read_thread.join
49
+
50
+ rescue DataSiftError => dse
51
+ puts "Error #{dse.message}"
52
+ case dse
53
+ when ConnectionError
54
+ when AuthError
55
+ when BadRequestError
56
+ puts "Error #{dse.message}"
57
+ end
58
+ end
59
+
60
+ #
61
+ # Push API endpoints
62
+ #
63
+ #
64
+
65
+ #def pushcreate(name)
66
+ # storage = Dscli::Storage.new
67
+ # endpoint = storage.get_push_endpoint(name)
68
+ # puts endpoint
69
+ #end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,69 @@
1
+ require 'thor'
2
+ require 'yaml'
3
+
4
+ module Dscli
5
+ class Commands < Thor
6
+ include Thor::Actions
7
+
8
+ def self.source_root
9
+ File.dirname(__FILE__)
10
+ end
11
+
12
+ desc 'config', 'Configure your DataSift API credentials'
13
+ option :user, type: :boolean, desc: 'Enter username and API key for your DataSift API user'
14
+ #option :push, type: :boolean, desc: 'Enter details of a new Push Destination'
15
+
16
+ def config
17
+
18
+ #if options[:user]
19
+ open(ENV['HOME'] + '/.datasiftcli', 'w') do |f|
20
+ f.write Dscli::Parameters.new.user_config(options).to_yaml
21
+ end
22
+ #end
23
+
24
+ #TODO Add other config options such as new push destinations
25
+ end
26
+
27
+ #
28
+ # Core API endpoints
29
+ # [ Missing /validate /balance ]
30
+ #
31
+
32
+ desc 'compile (csdl)', 'Compile CSDL'
33
+ def compile(csdl)
34
+ api = Dscli::API.new
35
+ definition = api.compile(csdl)
36
+ puts definition
37
+ end
38
+
39
+ desc 'usage [period]', 'Find your stream and license fee usage'
40
+ def usage(period = 'day')
41
+ api = Dscli::API.new
42
+ puts Yajl::Encoder.encode(api.usage(period), :pretty => true)
43
+ end
44
+
45
+ desc 'dpu (hash)', 'Find the DPU cost of a given stream hash'
46
+ def dpu(hash)
47
+ api = Dscli::API.new
48
+ puts Yajl::Encoder.encode(api.dpu(hash), :pretty => true)
49
+ end
50
+
51
+ desc 'stream (hash)', 'Stream interactions from a DataSift stream to the command line'
52
+ def stream(hash)
53
+ api = Dscli::API.new
54
+ api.stream(hash)
55
+ end
56
+
57
+ #
58
+ # Push API endpoints
59
+ #
60
+ #
61
+
62
+ #desc 'pushcreate', ''
63
+ #def pushcreate(name)
64
+ # api = Dscli::API.new
65
+ # api.pushcreate(name)
66
+ #end
67
+
68
+ end
69
+ end
@@ -0,0 +1,20 @@
1
+ require 'interact'
2
+
3
+ module Dscli
4
+ class Parameters
5
+ include Interactive
6
+
7
+ def user_config(options)
8
+
9
+ config = options.dup
10
+
11
+ username = ask "DataSift Username"
12
+ api_key = ask "DataSift API Key"
13
+
14
+ config = {:auth => {:username => username, :api_key => api_key}}
15
+
16
+ return config
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,52 @@
1
+ require 'yajl'
2
+
3
+ module Dscli
4
+ class Storage
5
+
6
+ def initialize
7
+ if !File.exist?(File.expand_path('~') + '/.datasiftcli')
8
+ @configfile = File.new(File.expand_path('~') + '/.datasiftcli', 'w')
9
+ @configfile.close
10
+ else
11
+ @configfile = File.expand_path('~') + '/.datasiftcli'
12
+ end
13
+ end
14
+
15
+ def set_auth(auth)
16
+ config = File.read(@configfile)
17
+ if config == ""
18
+ File.open(@configfile, "w") { |f|
19
+ f.write(Yajl::Encoder.encode(auth) + "\n")
20
+ }
21
+ end
22
+ #TODO Set 'else' to write over config if it already exists
23
+ end
24
+
25
+ def get_auth
26
+ config = YAML.load(File.read(@configfile))
27
+ end
28
+
29
+ # def add_push_endpoint(config)
30
+ # File.open(@configfile, 'a') { |f|
31
+ # f.puts Yajl::Encoder.encode(config) + "\n"
32
+ # }
33
+ # end
34
+
35
+ # def get_push_endpoint(name)
36
+ # parser = Yajl::Parser
37
+ # File.open(@configfile, 'r').each_line do |line|
38
+ # json = parser.parse(line)
39
+ # if json['name'] && json['name'] == name
40
+ # return json
41
+ # end
42
+ # end
43
+ # return ''
44
+ # end
45
+
46
+ # def list_push_endpoints
47
+ #
48
+ # end
49
+ #
50
+ #
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module Dscli
2
+ VERSION = "0.0.1"
3
+ end
data/lib/dscli.rb ADDED
@@ -0,0 +1,6 @@
1
+ dir = File.dirname(__FILE__)
2
+ require dir + '/Dscli/version'
3
+ require dir + '/Dscli/commands'
4
+ require dir + '/Dscli/api'
5
+ require dir + '/Dscli/storage'
6
+ require dir + '/Dscli/parameters'
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dscli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jason Dugdale
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: bundler
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: thor
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: yajl-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: datasift
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0.beta2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0.beta2
83
+ - !ruby/object:Gem::Dependency
84
+ name: interact
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: DS CLI is a CLI wrapper for the DataSift Ruby client library, allowing
98
+ you to make common DataSift API calls via the command line.
99
+ email:
100
+ - jason.dugdale@gmail.com
101
+ executables:
102
+ - dscli
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - bin/dscli
107
+ - lib/dscli/api.rb
108
+ - lib/dscli/commands.rb
109
+ - lib/dscli/parameters.rb
110
+ - lib/dscli/storage.rb
111
+ - lib/dscli/version.rb
112
+ - lib/dscli.rb
113
+ - LICENSE.txt
114
+ - README.md
115
+ homepage: https://github.com/dugjason/dscli
116
+ licenses:
117
+ - BSD
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.0.14
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Simple CLI wrapper for the DataSift Ruby client library
139
+ test_files: []