rbdash 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9a2d374b5d1b5aaa25c0b89f86e3ccb39792830
4
+ data.tar.gz: 55e09bdc3f91252b9c7b9c6e8f09eb1d44dff7e4
5
+ SHA512:
6
+ metadata.gz: 38fa957c9a89f2ad7e7fab4c413d8894f2f6fdcf867ce94d4a17f2054c2bdf2eae5d4c8dd22028d063f7355199a966d0cd41200d60a09ae8c103cdf2df7e4d13
7
+ data.tar.gz: 23d26a501859f1588003542135327d3451d2328b4fa97888991c8d14da6f360d2bf1ad8fba08fca4d78224a145d36a50b396110713554fb6167f528dbbe90609
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ queries
12
+ config.yml
13
+
14
+ # rspec failure tracking
15
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rbdash.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ NOTE: work in progress. :construction_worker:
2
+
3
+ # Rbdash
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rbdash`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'rbdash'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install rbdash
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rbdash.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rbdash'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config.sample.yml ADDED
@@ -0,0 +1,2 @@
1
+ base_uri: 'example.com'
2
+ token: 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
data/example.rb ADDED
@@ -0,0 +1,5 @@
1
+ require_relative 'client'
2
+
3
+ client = Rbdash::Client.new
4
+ client.queries
5
+ # client.update_query(28)
data/exe/rbdash ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbdash'
4
+ Rbdash::CLI.start(ARGV)
@@ -0,0 +1,8 @@
1
+ module Rbdash
2
+ class CLI::Pull
3
+ def run
4
+ queries = Rbdash::Models::Query.find_all
5
+ queries.each(&:save)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Rbdash
2
+ class CLI::Push
3
+ def run(id)
4
+ Rbdash::Models::Query.update(id)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ module Rbdash
2
+ class CLI::PushAll
3
+ def run
4
+ ids = Dir.glob('queries/*').map do |f|
5
+ f.match(/\d+/)[0]
6
+ end
7
+ ids.each.map do |id|
8
+ Rbdash::Models::Query.update(id)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
data/lib/rbdash/cli.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'thor'
2
+
3
+ module Rbdash
4
+ class CLI < Thor
5
+ class_option 'dry-run'
6
+
7
+ desc 'pull', 'pulls existing configurations.'
8
+
9
+ def pull
10
+ CLI::Pull.new.run
11
+ end
12
+
13
+ desc 'push <id>', 'push configurations'
14
+ def push(id)
15
+ CLI::Push.new.run(id)
16
+ end
17
+
18
+ desc 'push_all', 'push all configurations'
19
+ def push_all
20
+ CLI::PushAll.new.run
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,85 @@
1
+ require_relative '../request'
2
+
3
+ module Rbdash
4
+ module Models
5
+ class BaseModel
6
+ attr_accessor :body
7
+
8
+ def initialize(body)
9
+ @body = body
10
+ end
11
+
12
+ def to_json
13
+ JSON.pretty_generate(body)
14
+ end
15
+
16
+ def save
17
+ id = @body['id']
18
+ dirname = self.class.dirname
19
+ Dir.mkdir(dirname) unless File.exist?(dirname)
20
+ filename = "#{dirname}/query-#{id}.json"
21
+ File.open(filename, 'w+') do |f|
22
+ f.puts(to_json)
23
+ end
24
+ true
25
+ end
26
+
27
+ class << self
28
+ def client
29
+ Rbdash::Request.new
30
+ end
31
+
32
+ def find(id)
33
+ response = client.get("#{endpoint}/#{id}")
34
+ if response.code != 200
35
+ puts response.code
36
+ raise StandardError, 'abort!'
37
+ end
38
+ h = JSON.parse(response.body)
39
+ body = h.select { |k, _| attributes.map(&:to_s).include?(k) }
40
+ new(body)
41
+ end
42
+
43
+ def find_all
44
+ all_results = []
45
+ (1..100).each do |current_page|
46
+ response = client.get(endpoint.to_s, params: { page: current_page })
47
+ if response.code != 200
48
+ puts response.code
49
+ raise StandardError, 'abort!'
50
+ end
51
+ h = JSON.parse(response.body)
52
+ results = h['results']
53
+ all_results += results.map do |result|
54
+ body = result.select { |k, _| attributes.map(&:to_s).include?(k) }
55
+ new(body)
56
+ end
57
+
58
+ count = h['count']
59
+ page = h['page']
60
+ page_size = h['page_size']
61
+ break if count <= page * page_size
62
+ end
63
+ all_results
64
+ end
65
+
66
+ def update(id)
67
+ request_body = load(id).body
68
+ response = client.post("#{endpoint}/#{id}", body: request_body)
69
+ if response.code != 200
70
+ puts response.code
71
+ raise StandardError, 'abort!'
72
+ end
73
+ response
74
+ end
75
+
76
+ def load(id)
77
+ file = Dir.glob("#{dirname}/query-#{id}.json").first
78
+ raise StandardError, 'id not found' unless file
79
+ body = JSON.parse(File.read(file))
80
+ new(body)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'base_model'
2
+
3
+ module Rbdash
4
+ module Models
5
+ class Query < BaseModel
6
+ def self.attributes
7
+ [
8
+ :id, # number
9
+ :data_source_id, # number
10
+ :query, # string
11
+ :name, # string
12
+ :description, # string
13
+ :schedule, # string
14
+ :options # object
15
+ ]
16
+ end
17
+
18
+ def self.endpoint
19
+ '/queries'
20
+ end
21
+
22
+ def self.dirname
23
+ 'queries'
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ require 'yaml'
2
+ require 'httparty'
3
+ require 'json'
4
+
5
+ module Rbdash
6
+ class Request
7
+ include HTTParty
8
+
9
+ def initialize
10
+ config = YAML.load_file('./config.yml')
11
+ self.class.base_uri(config['base_uri'])
12
+ @default_options = {
13
+ verify: false,
14
+ headers: { 'Authorization' => config['token'] }
15
+ }
16
+ end
17
+
18
+ def get(ep, params: {}, options: {})
19
+ self.class.get(ep, @default_options.merge(options.merge(query: params)))
20
+ end
21
+
22
+ def post(ep, body: {}, options: {})
23
+ self.class.post(ep, @default_options.merge(options.merge(query: body)))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Rbdash
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/rbdash.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rbdash/version'
2
+
3
+ module Rbdash
4
+ require 'rbdash/cli'
5
+ require 'rbdash/cli/pull'
6
+ require 'rbdash/cli/push'
7
+ require 'rbdash/cli/push_all'
8
+ require 'rbdash/models/query'
9
+ end
data/rbdash.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rbdash/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'rbdash'
9
+ spec.version = Rbdash::VERSION
10
+ spec.authors = ['shotat']
11
+ spec.email = ['shotat@users.noreply.github.com']
12
+
13
+ spec.summary = 'Configuration management tools for re:dash'
14
+ spec.description = 'Configuration management tools for re:dash'
15
+ spec.homepage = 'https://github.com/shotat/rbdash'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'httparty'
25
+ spec.add_dependency 'thor'
26
+ spec.add_dependency 'diffy'
27
+ spec.add_development_dependency 'bundler', '~> 1.15'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbdash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - shotat
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: thor
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: diffy
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.15'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.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: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: Configuration management tools for re:dash
98
+ email:
99
+ - shotat@users.noreply.github.com
100
+ executables:
101
+ - rbdash
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - config.sample.yml
114
+ - example.rb
115
+ - exe/rbdash
116
+ - lib/rbdash.rb
117
+ - lib/rbdash/cli.rb
118
+ - lib/rbdash/cli/pull.rb
119
+ - lib/rbdash/cli/push.rb
120
+ - lib/rbdash/cli/push_all.rb
121
+ - lib/rbdash/models/base_model.rb
122
+ - lib/rbdash/models/query.rb
123
+ - lib/rbdash/request.rb
124
+ - lib/rbdash/version.rb
125
+ - rbdash.gemspec
126
+ homepage: https://github.com/shotat/rbdash
127
+ licenses: []
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.6.11
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Configuration management tools for re:dash
149
+ test_files: []