permutation-tools 0.2.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: 1d590e6fed36c7595c8397844ab89eadca25a2ab
4
+ data.tar.gz: 95f191de60e371e78ca7452c0cab8f29652f417d
5
+ SHA512:
6
+ metadata.gz: 3279d4a2e589e1cc7af23913c3b1ed01a186699dcf2d3ff89cdd3c4e5aca4edd8aa180870a5ae161df6e0d7546f094f0d67a565b5ffaa131d3eba7d5ddcaac74
7
+ data.tar.gz: b53d792d8fb41c62f2337d933e28e88816a4e27328647f9cee33d94167ec89c171adb6890575edbfcebd291b88ca25ef030b24a4b02b11afa0b0268ed413b3c2
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'faraday'
4
+ gem 'highline'
5
+ gem 'json'
6
+ gem 'semantic'
7
+ gem 'sinatra'
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "byebug"
13
+ gem "shoulda", ">= 0"
14
+ gem "rdoc", "~> 3.12"
15
+ gem "bundler", "~> 1.0"
16
+ gem "jeweler", "~> 2.0.1"
17
+ gem "simplecov", ">= 0"
18
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,97 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.1.7)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.3.6)
11
+ builder (3.2.2)
12
+ byebug (5.0.0)
13
+ columnize (= 0.9.0)
14
+ columnize (0.9.0)
15
+ descendants_tracker (0.0.4)
16
+ thread_safe (~> 0.3, >= 0.3.1)
17
+ docile (1.1.5)
18
+ faraday (0.9.0)
19
+ multipart-post (>= 1.2, < 3)
20
+ git (1.2.8)
21
+ github_api (0.12.2)
22
+ addressable (~> 2.3)
23
+ descendants_tracker (~> 0.0.4)
24
+ faraday (~> 0.8, < 0.10)
25
+ hashie (>= 3.3)
26
+ multi_json (>= 1.7.5, < 2.0)
27
+ nokogiri (~> 1.6.3)
28
+ oauth2
29
+ hashie (3.3.1)
30
+ highline (1.6.21)
31
+ i18n (0.6.11)
32
+ jeweler (2.0.1)
33
+ builder
34
+ bundler (>= 1.0)
35
+ git (>= 1.2.5)
36
+ github_api
37
+ highline (>= 1.6.15)
38
+ nokogiri (>= 1.5.10)
39
+ rake
40
+ rdoc
41
+ json (1.8.1)
42
+ jwt (1.0.0)
43
+ mini_portile (0.6.0)
44
+ minitest (5.4.2)
45
+ multi_json (1.10.1)
46
+ multi_xml (0.5.5)
47
+ multipart-post (2.0.0)
48
+ nokogiri (1.6.3.1)
49
+ mini_portile (= 0.6.0)
50
+ oauth2 (1.0.0)
51
+ faraday (>= 0.8, < 0.10)
52
+ jwt (~> 1.0)
53
+ multi_json (~> 1.3)
54
+ multi_xml (~> 0.5)
55
+ rack (~> 1.2)
56
+ rack (1.5.2)
57
+ rack-protection (1.5.2)
58
+ rack
59
+ rake (10.3.2)
60
+ rdoc (3.12.2)
61
+ json (~> 1.4)
62
+ semantic (1.3.0)
63
+ shoulda (3.5.0)
64
+ shoulda-context (~> 1.0, >= 1.0.1)
65
+ shoulda-matchers (>= 1.4.1, < 3.0)
66
+ shoulda-context (1.2.1)
67
+ shoulda-matchers (2.7.0)
68
+ activesupport (>= 3.0.0)
69
+ simplecov (0.9.1)
70
+ docile (~> 1.1.0)
71
+ multi_json (~> 1.0)
72
+ simplecov-html (~> 0.8.0)
73
+ simplecov-html (0.8.0)
74
+ sinatra (1.4.4)
75
+ rack (~> 1.4)
76
+ rack-protection (~> 1.4)
77
+ tilt (~> 1.3, >= 1.3.4)
78
+ thread_safe (0.3.4)
79
+ tilt (1.4.1)
80
+ tzinfo (1.2.2)
81
+ thread_safe (~> 0.1)
82
+
83
+ PLATFORMS
84
+ ruby
85
+
86
+ DEPENDENCIES
87
+ bundler (~> 1.0)
88
+ byebug
89
+ faraday
90
+ highline
91
+ jeweler (~> 2.0.1)
92
+ json
93
+ rdoc (~> 3.12)
94
+ semantic
95
+ shoulda
96
+ simplecov
97
+ sinatra
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Ian Hunter
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Permutation Tools
2
+
3
+ Command line tools for working with the permutation system
4
+
5
+ ## Installing
6
+
7
+ ```
8
+ bundle
9
+ rake install
10
+ ```
11
+
12
+ ## Commands
13
+
14
+ ### init
15
+
16
+ ```
17
+ permutation init
18
+ ```
19
+
20
+ Initialize permutation locally, will ask for username and password.
21
+
22
+ Note: Running commands which require authentication will automatically set this up.
23
+
24
+ ### server
25
+
26
+ ```
27
+ permutation server
28
+ ```
29
+
30
+ Run a webserver to mimic Permutation's router in production. Will serve all files from local directory.
31
+
32
+ ### mirror
33
+
34
+ ```
35
+ permutation mirror http://permutation.io
36
+ ```
37
+
38
+ Clone a website to the local directory.
39
+
40
+ ### release
41
+
42
+ ```
43
+ permutation release
44
+ ```
45
+
46
+ Cut a release to the Permutation web service.
data/Rakefile ADDED
@@ -0,0 +1,52 @@
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://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "permutation-tools"
18
+ gem.homepage = "http://github.com/ihunter/permutation-tools"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Tools for working with Permutation}
21
+ gem.description = %Q{}
22
+ gem.email = "ianhunter@gmail.com"
23
+ gem.authors = ["Ian Hunter"]
24
+ gem.executables = ['permutation']
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ desc "Code coverage detail"
37
+ task :simplecov do
38
+ ENV['COVERAGE'] = "true"
39
+ Rake::Task['test'].execute
40
+ end
41
+
42
+ task :default => :test
43
+
44
+ require 'rdoc/task'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "permutation-tools #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.1
data/bin/permutation ADDED
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "optparse"
4
+ require "semantic"
5
+ require 'json'
6
+ require 'highline/import'
7
+
8
+ require_relative '../lib/permutation-tools'
9
+
10
+ # FILE_NAME = '.permutation'
11
+
12
+ class String
13
+ def to_bool
14
+ return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
15
+ return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
16
+ raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
17
+ end
18
+ end
19
+
20
+ DEBUG = ENV['DEBUG'] ? ENV['DEBUG'].to_bool : false
21
+
22
+ case ARGV[0]
23
+ when "mirror", "m"
24
+ # Permutation::Mirror.create(args.shift)
25
+ raise "Pending ..."
26
+ when "release", "r"
27
+ Permutation::Release.create Permutation::Release.parse_args(ARGV)
28
+ when "server", "s"
29
+ p = 8080
30
+ require_relative '../lib/tools/server'
31
+ module Permutation
32
+ class Server < Sinatra::Application
33
+ set :port, 8080
34
+ end
35
+ end
36
+
37
+ # Thread.new do
38
+ # sleep(1)
39
+ # `open http://localhost:#{p}`
40
+ # end
41
+ Permutation::Server.run!
42
+ when "version"
43
+ puts Permutation::Config.version
44
+ when "init"
45
+ Permutation::Config.init
46
+ else
47
+ usage()
48
+ end
49
+
50
+ BEGIN {
51
+ def usage
52
+ puts "Usage: permutation COMMAND"
53
+ puts
54
+ puts "Commands:"
55
+ puts " init: Initialize the project"
56
+ puts " release: Release a version"
57
+ puts " version: Show the current version"
58
+ end
59
+
60
+ def run(cmd)
61
+ puts " -> #{cmd}"
62
+ `#{cmd}`
63
+ end
64
+ }
data/index.html ADDED
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title></title>
6
+ </head>
7
+ <body>
8
+ OK
9
+ <script type="text/javascript">
10
+ $P.geolocate(function(data){
11
+ console.log(data)
12
+ })
13
+ </script>
14
+ </body>
15
+ </html>
@@ -0,0 +1,171 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'openssl'
4
+
5
+ class Scraper
6
+ attr_accessor :source, :name
7
+
8
+ def initialize(source, name)
9
+ @source = source
10
+ @name = name
11
+ @AppRoot = File.join(Dir.pwd, name)
12
+ end
13
+
14
+ def open(*args)
15
+ super *args, allow_redirections: :safe, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE
16
+ end
17
+
18
+ def scrap
19
+ system 'mkdir', '-p', @AppRoot
20
+ scraproot = @AppRoot
21
+ system 'mkdir', '-p', scraproot + "/img"
22
+ system 'mkdir', '-p', scraproot + "/js"
23
+ system 'mkdir', '-p', scraproot + "/css"
24
+
25
+ page = Nokogiri::HTML(open(@source))
26
+
27
+ e = /^.*\.(jpg|JPG|gif|GIF|png|PNG|tiff|tif|TIFF|TIF)/
28
+
29
+ n=0
30
+ page.xpath('//img/@data-src', '//img/@src').each do |img|
31
+ # asset_name = '/img/' + n.to_s + File.basename(img.value, ".*") + "." +
32
+ # e.match(File.extname(img.value)).to_a.last.to_s
33
+ asset_name = img.value
34
+ filename = scraproot + asset_name
35
+ system 'mkdir', '-p', File.dirname(filename)
36
+
37
+ open(filename , 'wb') do |file|
38
+ puts "Writing #{filename}"
39
+ file << open(URI.join( @source, img.value ).to_s).read
40
+ img.content = asset_name
41
+ end
42
+ n += 1
43
+ end
44
+
45
+ n=0
46
+ page.xpath('//link/@href').each do |link|
47
+ asset_name = '/css/' + n.to_s + ".css"
48
+ filename = scraproot + asset_name
49
+ open(filename, 'wb') do |file|
50
+ puts "Writing #{filename}"
51
+ begin
52
+ open(URI.join( @source, link.value ).to_s).read
53
+ rescue
54
+ else
55
+ file << open(URI.join( @source, link.value ).to_s).read
56
+ end
57
+ link.content = asset_name
58
+ end
59
+ n = n + 1
60
+ end
61
+
62
+ n=0
63
+ page.xpath('//script/@src').each do |script|
64
+ asset_name = '/js/' + n.to_s + File.basename(script.value)
65
+ filename = scraproot + asset_name
66
+ open(filename, 'wb') do |file|
67
+ puts "Writing #{filename}"
68
+ file << open(URI.join( @source, script.value ).to_s).read
69
+ script.content = asset_name
70
+ end
71
+ n = n + 1
72
+ end
73
+ open(scraproot + "/" + "index.html", "wb") do |file|
74
+ puts "Writing #{scraproot + "/" + "index.html"}"
75
+ file.write(page)
76
+ end
77
+ end
78
+ end
79
+
80
+ #####
81
+ # Patch to allow open-uri to follow safe (http to https)
82
+ # and unsafe redirections (https to http).
83
+ #
84
+ # Original gist URL:
85
+ # https://gist.github.com/1271420
86
+ #
87
+ # Relevant issue:
88
+ # http://redmine.ruby-lang.org/issues/3719
89
+ #
90
+ # Source here:
91
+ # https://github.com/ruby/ruby/blob/trunk/lib/open-uri.rb
92
+ #
93
+ # Thread-safe implementation adapted from:
94
+ # https://github.com/obfusk/open_uri_w_redirect_to_https
95
+ #
96
+ module OpenURI
97
+ class <<self
98
+ alias_method :open_uri_original, :open_uri
99
+ alias_method :redirectable_cautious?, :redirectable?
100
+
101
+ def redirectable?(uri1, uri2)
102
+ case Thread.current[:__open_uri_redirections__]
103
+ when :safe
104
+ redirectable_safe? uri1, uri2
105
+ when :all
106
+ redirectable_all? uri1, uri2
107
+ else
108
+ redirectable_cautious? uri1, uri2
109
+ end
110
+ end
111
+
112
+ def redirectable_safe?(uri1, uri2)
113
+ redirectable_cautious?(uri1, uri2) || http_to_https?(uri1, uri2)
114
+ end
115
+
116
+ def redirectable_all?(uri1, uri2)
117
+ redirectable_safe?(uri1, uri2) || https_to_http?(uri1, uri2)
118
+ end
119
+ end
120
+
121
+ #####
122
+ # Patches the original open_uri method, so that it accepts the
123
+ # :allow_redirections argument with these options:
124
+ #
125
+ # * :safe will allow HTTP => HTTPS redirections.
126
+ # * :all will allow HTTP => HTTPS and HTTPS => HTTP redirections.
127
+ #
128
+ # OpenURI::open can receive different kinds of arguments, like a string for
129
+ # the mode or an integer for the permissions, and then a hash with options
130
+ # like UserAgent, etc.
131
+ #
132
+ # To find the :allow_redirections option, we look for this options hash.
133
+ #
134
+ def self.open_uri(name, *rest, &block)
135
+ Thread.current[:__open_uri_redirections__] = allow_redirections(rest)
136
+
137
+ block2 = lambda do |io|
138
+ Thread.current[:__open_uri_redirections__] = nil
139
+ block[io]
140
+ end
141
+
142
+ begin
143
+ open_uri_original name, *rest, &(block ? block2 : nil)
144
+ ensure
145
+ Thread.current[:__open_uri_redirections__] = nil
146
+ end
147
+ end
148
+
149
+ private
150
+
151
+ def self.allow_redirections(args)
152
+ options = first_hash_argument(args)
153
+ options.delete :allow_redirections if options
154
+ end
155
+
156
+ def self.first_hash_argument(arguments)
157
+ arguments.select { |arg| arg.is_a? Hash }.first
158
+ end
159
+
160
+ def self.http_to_https?(uri1, uri2)
161
+ schemes_from([uri1, uri2]) == %w(http https)
162
+ end
163
+
164
+ def self.https_to_http?(uri1, uri2)
165
+ schemes_from([uri1, uri2]) == %w(https http)
166
+ end
167
+
168
+ def self.schemes_from(uris)
169
+ uris.map { |u| u.scheme.downcase }
170
+ end
171
+ end
@@ -0,0 +1,11 @@
1
+ require 'etc'
2
+ require 'faraday'
3
+ require 'open-uri'
4
+ require 'nokogiri'
5
+
6
+ require_relative 'ext/scraper'
7
+
8
+ require_relative 'tools/api'
9
+ require_relative 'tools/config'
10
+ require_relative 'tools/mirror'
11
+ require_relative 'tools/release'
data/lib/tools/api.rb ADDED
@@ -0,0 +1,48 @@
1
+ module Permutation
2
+ class API
3
+ DEFAULT_HOST = "http://app.permutation.io"
4
+
5
+ class Response
6
+ def initialize(status, body)
7
+ @status = status
8
+ @body = body
9
+ end
10
+
11
+ attr_reader :status
12
+ def body
13
+ @parsed_body ||= JSON.parse @body, symbolize_names: false
14
+ end
15
+ end
16
+
17
+ class << self
18
+ def get(url, headers={})
19
+ conn = Faraday.new(:url => host) do
20
+ faraday.response :logger if ENV['DEBUG'] # log requests to STDOUT
21
+ end
22
+ conn.headers = headers
23
+ response = conn.get url
24
+ # puts response.body
25
+ Response.new(response.status, response.body)
26
+ end
27
+
28
+ def post(url, params={}, headers={})
29
+ conn = Faraday.new(:url => host) do |faraday|
30
+ faraday.request :url_encoded # form-encode POST params
31
+ faraday.response :logger if ENV['DEBUG'] # log requests to STDOUT
32
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
33
+ end
34
+
35
+ conn.headers = headers
36
+
37
+ response = conn.post url, params
38
+ Response.new(response.status, response.body)
39
+ end
40
+
41
+ def host
42
+ @host = ENV['HOST'] ||
43
+ Permutation::Config.account['host'] ||
44
+ DEFAULT_HOST
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,80 @@
1
+ module Permutation
2
+ class Config
3
+ class << self
4
+ ACCOUNT_CONFIG_FILE = File.join(Etc.getpwuid.dir, '.permutation')
5
+ REPOSITORY_CONFIG_FILE = File.join(Dir.pwd, '.permutation')
6
+
7
+ def account
8
+ Permutation::Config.read(ACCOUNT_CONFIG_FILE) || begin
9
+ access_token = nil
10
+ json = {}
11
+
12
+ puts "Log In to Permutation"
13
+ email = ask("Email: ")
14
+ password = ask("Password: ") {|q| q.echo = false}
15
+
16
+ response = Permutation::API.post '/api/session.json', { email: email, password: password }
17
+ if response.status == 201
18
+ session = response.body.select{|k,_| ["email","access_token"].include? k}
19
+ json.merge! session
20
+ json.merge! host: Permutation::API.host unless Permutation::API.host == Permutation::API::DEFAULT_HOST
21
+
22
+ write(json, ACCOUNT_CONFIG_FILE)
23
+ json
24
+ else
25
+ puts
26
+ puts "Invalid login credentials"
27
+ exit
28
+ end
29
+ end
30
+ end
31
+
32
+ # def repository
33
+ # regex = /git@github\.com|git@bitbucket\.org:(.*)\.git/
34
+ # Permutation::Config.read(REPOSITORY_CONFIG_FILE) || begin
35
+ # json = {}
36
+ # account_config = account
37
+ # `git remote show origin | grep Fetch | cut -d: -f2-`.match(regex)
38
+ # repo_name = $1
39
+ #
40
+ # repos = Permutation::API.get('/api/repositories.json', 'Access-Token' => account_config['access_token']).body
41
+ # if repo = repos['repositories'].detect{|repo| repo['name'] == repo_name}
42
+ # json.merge! 'repo' => repo['name']
43
+ # write(json, REPOSITORY_CONFIG_FILE)
44
+ # json
45
+ # else
46
+ # puts "Unable to find repo #{repo_name}"
47
+ # end
48
+ # end
49
+ # end
50
+ end
51
+
52
+
53
+ class << self
54
+ def write(json, file)
55
+ puts "Writing to #{file}" if DEBUG
56
+
57
+ _file = File.open( file, "w+" )
58
+ _file.write(JSON.pretty_generate(json))
59
+ _file.close
60
+ end
61
+
62
+ def read(file)
63
+ return JSON.parse( IO.read(file), symbolize_names: false )
64
+ rescue
65
+ nil
66
+ end
67
+
68
+ def version
69
+ read["version"]
70
+ end
71
+
72
+ private
73
+
74
+ def not_setup!
75
+ puts "Permutation is not setup, please run 'permutation init'"
76
+ exit 1
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,19 @@
1
+ module Permutation
2
+ class Mirror
3
+ class << self
4
+ def create(url)
5
+ if url.nil?
6
+ error "URL not specified"
7
+ end
8
+ # `wget --mirror --convert-links --adjust-extension --page-requisites #{url}`
9
+ web = Scraper.new(url , ".")
10
+ web.scrap
11
+ end
12
+
13
+ def error(message)
14
+ puts message
15
+ exit
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,72 @@
1
+ module Permutation
2
+ class Release
3
+ class << self
4
+ def create(options)
5
+ account_config = Permutation::Config.account
6
+
7
+ remote_branch = `git rev-parse --abbrev-ref --symbolic-full-name @{u}`
8
+ sha = `git rev-parse #{remote_branch}`
9
+
10
+ regex = /(git@github\.com|git@bitbucket\.org):(.*)\.git/
11
+ `git remote show origin | grep Fetch | cut -d: -f2-`.match(regex)
12
+ repo_name = $2
13
+
14
+ response = Permutation::API.post(
15
+ '/api/releases.json',
16
+ options.merge({
17
+ sha: sha,
18
+ repo_name: repo_name
19
+ }),
20
+ { 'Access-Token' => account_config['access_token'] }
21
+ )
22
+
23
+ if response.status == 201
24
+ response.body["releases"].each do |release|
25
+ puts "Created release #{release['version']} for #{release['account']['name']}"
26
+ end
27
+ elsif response.status == 401
28
+ puts "Unauthorized, please re-run permutation init"
29
+ exit
30
+ elsif response.status == 404
31
+ puts "Repository #{repo_name} not found"
32
+ exit
33
+ else
34
+ puts "Error"
35
+ end
36
+ end
37
+
38
+ def error(message)
39
+ puts message
40
+ exit
41
+ end
42
+
43
+ def parse_args(args)
44
+ options = {}
45
+ OptionParser.new do |opts|
46
+ opts.banner = "Usage: permutation release [options]"
47
+ opts.separator ""
48
+ opts.separator "Options:"
49
+ # opts.on("-p", "--parent PARENT") do |v|
50
+ # options[:parent] = v
51
+ # end
52
+
53
+ opts.on("-i", "--iterate [ITERATE]", "Iterate using the new release") do |v|
54
+ options[:iterate] = v
55
+ end
56
+
57
+ opts.on("-b", "--bump [BUMP]", [:major, :minor, :patch]) do |v|
58
+ options[:bump] = v
59
+ end
60
+ end.parse!
61
+
62
+ options
63
+ end
64
+
65
+ private
66
+
67
+ def config
68
+ @config ||= Permutation::Config.read
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,114 @@
1
+ require 'open-uri'
2
+ require 'sinatra'
3
+ require 'byebug'
4
+
5
+ module Permutation
6
+ class Server < Sinatra::Application
7
+ set :static, false
8
+ set :bind, '0.0.0.0'
9
+
10
+ after do
11
+ if response.headers["Content-Type"] &&
12
+ response.headers["Content-Type"].include?("text/html")
13
+
14
+ script_host = ENV['SCRIPT_HOST'] || "http://permutation-cdn.s3.amazonaws.com"
15
+
16
+ response.body.each do |part|
17
+ insert_at = part.index('<head>') + 6
18
+ unless insert_at.nil?
19
+ part.insert(insert_at, %%
20
+ <script type='text/javascript' src='#{script_host}/permutation.js'></script>
21
+ <script type='text/javascript'>
22
+ $P.init();
23
+ </script>
24
+ %)
25
+ end
26
+ end
27
+
28
+ new_size = 0
29
+ response.body.each{|part| new_size += part.bytesize}
30
+ response.headers.merge!("Content-Length" => new_size.to_s)
31
+ end
32
+ end
33
+
34
+ get '/api/*' do
35
+ host = ENV['API_HOST'] || "http://router.permutation.io"
36
+ url = "/api/"
37
+ if splat = params.delete('splat')
38
+ url += splat.join
39
+ end
40
+
41
+ conn = Faraday.new(url: host) do |faraday|
42
+ faraday.request :url_encoded
43
+ faraday.response :logger
44
+ faraday.adapter Faraday.default_adapter
45
+ end
46
+
47
+ res = conn.get url
48
+ status res.status
49
+ res.body
50
+ end
51
+
52
+ post '/api/*' do
53
+ host = ENV['API_HOST'] || "http://router.permutation.io"
54
+ url = "/api/"
55
+ if splat = params.delete('splat')
56
+ url += splat.join
57
+ end
58
+
59
+ conn = Faraday.new(url: host) do |faraday|
60
+ faraday.request :url_encoded
61
+ # faraday.response :logger
62
+ faraday.adapter Faraday.default_adapter
63
+ end
64
+
65
+ res = conn.post url, params
66
+ status res.status
67
+ res.body
68
+ end
69
+
70
+ get '*' do
71
+ uri = params[:splat].first
72
+ uri = '/index.html' if uri =~ /^\/$/
73
+
74
+ f = File.join('.', uri)
75
+ if File.directory?(f)
76
+ uri += "/index.html"
77
+ f = File.join('.', uri)
78
+ end
79
+
80
+ if File.exists?(f) && File.file?(f)
81
+ if uri =~ /\.html$/
82
+ response.headers['Content-Type'] = `file --mime -b #{f}`
83
+ File.read(f)
84
+ else
85
+ send_file f
86
+ end
87
+ else
88
+ status 404
89
+ "Not Found"
90
+ end
91
+ end
92
+
93
+ post ('*') { catchall }
94
+ put ('*') { catchall }
95
+ patch ('*') { catchall }
96
+ delete ('*') { catchall }
97
+ options ('*') { catchall }
98
+
99
+ private
100
+
101
+ def catchall
102
+
103
+ params.delete 'splat'
104
+ params.delete 'captures'
105
+
106
+ puts
107
+ puts "Conversion!"
108
+ puts " params: #{params.inspect}"
109
+ puts
110
+
111
+ status 201
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,76 @@
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
+ # stub: permutation-tools 0.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "permutation-toolbelt"
9
+ s.version = "0.2.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Ian Hunter"]
14
+ s.date = "2014-11-03"
15
+ s.description = ""
16
+ s.email = "ian@permutation.io"
17
+ s.executables = ["permutation"]
18
+ s.extra_rdoc_files = [
19
+ "LICENSE.txt",
20
+ "README.rdoc"
21
+ ]
22
+ s.files = [
23
+ ".document",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "bin/permutation",
31
+ "lib/permutation-tools.rb",
32
+ "permutation-tools.gemspec",
33
+ "test/helper.rb",
34
+ "test/test_permutation-tools.rb"
35
+ ]
36
+ s.homepage = "http://github.com/permutation.io/toolbelt"
37
+ s.licenses = ["MIT"]
38
+ s.rubygems_version = "2.2.2"
39
+ s.summary = "Tools for working with Permutation"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 4
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<faraday>, [">= 0"])
46
+ s.add_runtime_dependency(%q<highline>, [">= 0"])
47
+ s.add_runtime_dependency(%q<json>, [">= 0"])
48
+ s.add_runtime_dependency(%q<semantic>, [">= 0"])
49
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
53
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<faraday>, [">= 0"])
56
+ s.add_dependency(%q<highline>, [">= 0"])
57
+ s.add_dependency(%q<json>, [">= 0"])
58
+ s.add_dependency(%q<semantic>, [">= 0"])
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
63
+ s.add_dependency(%q<simplecov>, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<faraday>, [">= 0"])
67
+ s.add_dependency(%q<highline>, [">= 0"])
68
+ s.add_dependency(%q<json>, [">= 0"])
69
+ s.add_dependency(%q<semantic>, [">= 0"])
70
+ s.add_dependency(%q<shoulda>, [">= 0"])
71
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
72
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
73
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
74
+ s.add_dependency(%q<simplecov>, [">= 0"])
75
+ end
76
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ require 'rubygems'
18
+ require 'bundler'
19
+ begin
20
+ Bundler.setup(:default, :development)
21
+ rescue Bundler::BundlerError => e
22
+ $stderr.puts e.message
23
+ $stderr.puts "Run `bundle install` to install missing gems"
24
+ exit e.status_code
25
+ end
26
+ require 'test/unit'
27
+ require 'shoulda'
28
+
29
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
31
+ require 'permutation-tools'
32
+
33
+ class Test::Unit::TestCase
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestPermutationTools < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,218 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: permutation-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Ian Hunter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
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: highline
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: json
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: semantic
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: sinatra
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: shoulda
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
+ - !ruby/object:Gem::Dependency
112
+ name: rdoc
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.12'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.12'
125
+ - !ruby/object:Gem::Dependency
126
+ name: bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: jeweler
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 2.0.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 2.0.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: ''
168
+ email: ianhunter@gmail.com
169
+ executables:
170
+ - permutation
171
+ extensions: []
172
+ extra_rdoc_files:
173
+ - LICENSE.txt
174
+ - README.md
175
+ files:
176
+ - Gemfile
177
+ - Gemfile.lock
178
+ - LICENSE.txt
179
+ - README.md
180
+ - Rakefile
181
+ - VERSION
182
+ - bin/permutation
183
+ - index.html
184
+ - lib/ext/scraper.rb
185
+ - lib/permutation-tools.rb
186
+ - lib/tools/api.rb
187
+ - lib/tools/config.rb
188
+ - lib/tools/mirror.rb
189
+ - lib/tools/release.rb
190
+ - lib/tools/server.rb
191
+ - permutation-tools.gemspec
192
+ - test/helper.rb
193
+ - test/test_permutation-tools.rb
194
+ homepage: http://github.com/ihunter/permutation-tools
195
+ licenses:
196
+ - MIT
197
+ metadata: {}
198
+ post_install_message:
199
+ rdoc_options: []
200
+ require_paths:
201
+ - lib
202
+ required_ruby_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ required_rubygems_version: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ version: '0'
212
+ requirements: []
213
+ rubyforge_project:
214
+ rubygems_version: 2.4.6
215
+ signing_key:
216
+ specification_version: 4
217
+ summary: Tools for working with Permutation
218
+ test_files: []