plunk_it 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2-p180@plunkit_1_9_2 --create
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'multi_json'
4
+ gem 'mechanize'
5
+ group :development do
6
+ # gem "shoulda", ">= 0"
7
+ gem "rdoc", "~> 3.12"
8
+ gem "bundler"
9
+ gem "jeweler", "~> 1.8.4"
10
+ # gem "rcov", ">= 0"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ domain_name (0.5.7)
5
+ unf (~> 0.0.3)
6
+ git (1.2.5)
7
+ jeweler (1.8.4)
8
+ bundler (~> 1.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ rdoc
12
+ json (1.7.7)
13
+ mechanize (2.5.1)
14
+ domain_name (~> 0.5, >= 0.5.1)
15
+ mime-types (~> 1.17, >= 1.17.2)
16
+ net-http-digest_auth (~> 1.1, >= 1.1.1)
17
+ net-http-persistent (~> 2.5, >= 2.5.2)
18
+ nokogiri (~> 1.4)
19
+ ntlm-http (~> 0.1, >= 0.1.1)
20
+ webrobots (~> 0.0, >= 0.0.9)
21
+ mime-types (1.21)
22
+ multi_json (1.5.0)
23
+ net-http-digest_auth (1.2.1)
24
+ net-http-persistent (2.8)
25
+ nokogiri (1.5.6)
26
+ ntlm-http (0.1.1)
27
+ rake (0.9.2.2)
28
+ rdoc (3.12.1)
29
+ json (~> 1.4)
30
+ unf (0.0.5)
31
+ unf_ext
32
+ unf_ext (0.0.5)
33
+ webrobots (0.0.13)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler
40
+ jeweler (~> 1.8.4)
41
+ mechanize
42
+ multi_json
43
+ rdoc (~> 3.12)
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 Dirk Elmendorf, r26D LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,29 @@
1
+ = plunk_it
2
+
3
+ This is a small script to handle uploading a set of files to (Plunker)[http://plnkr.co] and keep them in sync
4
+
5
+ == Getting Started
6
+
7
+ You need to get you GitHub token for Plunker. I did this by using chrome to inspect what I post after logging in. There is probably a better way to handle this - if you can figure it out - let me know :)
8
+
9
+ You need to create a file ~/.plunk_it with just the bare token
10
+
11
+ After that you should be able to run the command on any directory you want
12
+
13
+
14
+
15
+ == Contributing to plunk_it
16
+
17
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
18
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
19
+ * Fork the project.
20
+ * Start a feature/bugfix branch.
21
+ * Commit and push until you are happy with your contribution.
22
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
23
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
24
+
25
+ == Copyright
26
+
27
+ Copyright (c) 2013 Dirk Elmendorf & r26D LLC. See LICENSE.txt for
28
+ further details.
29
+
data/Rakefile ADDED
@@ -0,0 +1,46 @@
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 = "plunk_it"
18
+ gem.homepage = "http://github.com/delmendo/plunk_it"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Makes it easy to push code to http://plnkr.co}
21
+ gem.description = %Q{This gem gives you a command line tool to keep your code in sync with plunks you publish at http://plnkr.co}
22
+ gem.email = "code@r26d.com"
23
+ gem.authors = ["Dirk Elmendorf"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+
36
+ task :default => :test
37
+
38
+ require 'rdoc/task'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "plunk_it #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/_rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2-p180@plunkit_1_9_2 --create
data/bin/plunk_it ADDED
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env ruby
2
+ require 'yaml'
3
+ require 'multi_json'
4
+ require 'nokogiri'
5
+ require 'mechanize'
6
+ require 'logger'
7
+ #TODO - allow you to configure what gets excluded from uploading
8
+ #TODO - add support for pulling down a plunk to keep the local file in sync
9
+ #TODO - build as a gem
10
+
11
+ VALID_EXTENSTIONS = [".js", ".html"]
12
+ if !File.exists?(File.expand_path("~/.plunk_it"))
13
+ abort("You must created a ~/.plunk_it with your GitHubToken")
14
+ else
15
+ GITHUB_TOKEN = File.open(File.expand_path("~/.plunk_it"), "rb").read
16
+ end
17
+
18
+ target_directory = ARGV.first
19
+ abort("You must provide the name of a directory to plunk") if !target_directory
20
+ puts "Preparing to plunk #{target_directory}"
21
+
22
+ #open the manifest - which should have
23
+ # the url
24
+ # the description
25
+ # the tags for the item
26
+ # get the authentication from a file or env?
27
+ abort "#{target_directory} is not a valid directory" if !FileTest.directory?(target_directory)
28
+ abort("You do not have permission to read #{target_directory}") if !FileTest.readable?(target_directory)
29
+ Dir.chdir(target_directory)
30
+ manifest_filename = File.expand_path([target_directory, "manifest.yml"].join(File::SEPARATOR))
31
+ abort("You must have a manifest.yml file in directory it to be able to be plunked") if !File.exists?(manifest_filename)
32
+ puts "Unable to save the plunker id because the manifest is not writable" if !FileTest.writable?(manifest_filename)
33
+ manifest = YAML.load_file(manifest_filename)
34
+
35
+ payload = manifest.clone
36
+ payload.delete("plnkr_id")
37
+ payload["files"] = {} if !payload["files"]
38
+ #payload["description"] += " #{Time.now}"
39
+
40
+ #get a list of the files in the directory - exclude the manifest
41
+ puts "Bundling files:"
42
+ Dir["**/*"].select{|x| !File.directory?(x) &&
43
+ VALID_EXTENSTIONS.include?(File.extname(x))}.each do |file_name|
44
+ puts "\t#{file_name}"
45
+ file = File.open(file_name, "rb")
46
+ payload["files"][file_name] = { :filename => file_name,
47
+ :content => file.read}
48
+
49
+ end
50
+ @agent = Mechanize.new do|a|
51
+ #a.log = Logger.new('log.txt')
52
+ # a.log.level = Logger::DEBUG
53
+ # a.user_agent_alias = "Windows IE 6"
54
+ end
55
+ plnkr_session_page = @agent.get("http://api.plnkr.co/session")
56
+ plnkr_session = MultiJson.load(plnkr_session_page.body)
57
+ login_post = @agent.post(plnkr_session["user_url"], MultiJson.dump({"service" => "github",
58
+ "token" => GITHUB_TOKEN}),
59
+ {"Content-type" => "application/json;charset=UTF-8",
60
+ "Origin" => "http://www.plnkr.co",
61
+ "Referer" => "http://www.plnkr.co/"})
62
+
63
+ #figure out if they have plunked it before
64
+ if manifest["plnkr_id"]
65
+ post_url = "http://api.plnkr.co/plunks/#{manifest["plnkr_id"]}?sessid=#{plnkr_session["id"]}"
66
+ #payload.delete("tags") #Tags have to be handled in a seperate request
67
+ referer = "http://plnkr.co/edit/#{manifest["plnkr_id"]}"
68
+ current_data_page = @agent.get(post_url)
69
+ current_data = MultiJson.load(current_data_page.body)
70
+ payload.delete("description") if current_data["description"] == payload["description"]
71
+ payload.delete("private") if current_data["private"] == payload["private"]
72
+ payload.delete("tags")
73
+ new_tags = {}
74
+ manifest["tags"].each do |tag|
75
+ if !current_data["tags"].include?(tag)
76
+ new_tags[tag] = true
77
+ end
78
+ end
79
+ current_data["tags"].each do |tag|
80
+ if !manifest["tags"].include?(tag)
81
+ new_tags[tag] = nil
82
+ end
83
+ end
84
+ payload["tags"] = new_tags if !new_tags.empty?
85
+
86
+ new_files = {}
87
+ payload["files"].each do |file, value|
88
+ if !current_data["files"].has_key?(file)
89
+ puts "New file found #{file}"
90
+ new_files[file] = value
91
+ else
92
+ if current_data["files"][file]["content"] != value[:content]
93
+ puts "File modified #{file}"
94
+ # puts "Server:"
95
+ # pp current_data["files"][file]["content"]
96
+ # puts "Local:"
97
+ # pp value[:content]
98
+ new_files[file] = { "content" => value[:content]}
99
+ else
100
+ puts "Ignoring #{file}"
101
+ end
102
+ end
103
+
104
+ end
105
+ current_data["files"].each do |file,value|
106
+ if !payload["files"].has_key?(file)
107
+ puts "Removing File #{file}"
108
+ new_files[file] = nil
109
+ end
110
+ end
111
+
112
+ # figure out i fthere are files that have chnaged
113
+ if new_files.empty?
114
+ payload.delete("files")
115
+ else
116
+ payload["files"] = new_files
117
+ end
118
+
119
+ #pp payload
120
+ # pp MultiJson.dump(payload)
121
+ # abort("oops")
122
+ else
123
+ post_url = "http://api.plnkr.co/plunks?sessid=#{plnkr_session["id"]}"
124
+ referer = "http://plnkr.co/edit/"
125
+ current_data_page = @agent.get(post_url)
126
+ end
127
+
128
+ plunk_post = @agent.post(post_url, MultiJson.dump(payload),
129
+ {"Content-type" => "application/json;charset=UTF-8",
130
+ "Host" => "api.plnkr.co",
131
+ "Origin" => "http://plnkr.co",
132
+ "Referer" => referer })
133
+
134
+
135
+ plunk_data = MultiJson.load(plunk_post.body)
136
+ manifest["plnkr_id"] = plunk_data["id"]
137
+ File.open(manifest_filename, "wb") do |f|
138
+ f.write(YAML.dump(manifest))
139
+ end
140
+ puts "It has been plunked to http://plnkr.co/edit/#{plunk_data["id"]}"
data/lib/plunk_it.rb ADDED
File without changes
data/plunk_it.gemspec ADDED
@@ -0,0 +1,69 @@
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 = "plunk_it"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dirk Elmendorf"]
12
+ s.date = "2013-02-11"
13
+ s.description = "This gem gives you a command line tool to keep your code in sync with plunks you publish at http://plnkr.co"
14
+ s.email = "code@r26d.com"
15
+ s.executables = ["plunk_it"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rvmrc",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "_rvmrc",
30
+ "bin/plunk_it",
31
+ "lib/plunk_it.rb",
32
+ "plunk_it.gemspec",
33
+ "sample/example.js",
34
+ "sample/index.html",
35
+ "sample/manifest.yml",
36
+ "test/helper.rb",
37
+ "test/test_plunk_it.rb"
38
+ ]
39
+ s.homepage = "http://github.com/delmendo/plunk_it"
40
+ s.licenses = ["MIT"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = "1.8.24"
43
+ s.summary = "Makes it easy to push code to http://plnkr.co"
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<multi_json>, [">= 0"])
50
+ s.add_runtime_dependency(%q<mechanize>, [">= 0"])
51
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
52
+ s.add_development_dependency(%q<bundler>, [">= 0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
54
+ else
55
+ s.add_dependency(%q<multi_json>, [">= 0"])
56
+ s.add_dependency(%q<mechanize>, [">= 0"])
57
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
58
+ s.add_dependency(%q<bundler>, [">= 0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<multi_json>, [">= 0"])
63
+ s.add_dependency(%q<mechanize>, [">= 0"])
64
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
+ s.add_dependency(%q<bundler>, [">= 0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
67
+ end
68
+ end
69
+
data/sample/example.js ADDED
@@ -0,0 +1,3 @@
1
+ function alert_me() {
2
+ alert("I'm triggered!");
3
+ }
data/sample/index.html ADDED
@@ -0,0 +1,7 @@
1
+ <html>
2
+ <head>
3
+ <title>My First Plunk</title>
4
+ <script src="example.js"></script>
5
+ </head>
6
+ <body>Hello Nurse!</body>
7
+ </html>
@@ -0,0 +1,6 @@
1
+ description: This is step 2
2
+ private: false
3
+ tags:
4
+ - angularjs
5
+ - code
6
+ - plunker_it
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'plunk_it'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestPlunkIt < 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,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plunk_it
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dirk Elmendorf
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: multi_json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mechanize
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.12'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.8.4
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.8.4
94
+ description: This gem gives you a command line tool to keep your code in sync with
95
+ plunks you publish at http://plnkr.co
96
+ email: code@r26d.com
97
+ executables:
98
+ - plunk_it
99
+ extensions: []
100
+ extra_rdoc_files:
101
+ - LICENSE.txt
102
+ - README.rdoc
103
+ files:
104
+ - .document
105
+ - .rvmrc
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.rdoc
110
+ - Rakefile
111
+ - VERSION
112
+ - _rvmrc
113
+ - bin/plunk_it
114
+ - lib/plunk_it.rb
115
+ - plunk_it.gemspec
116
+ - sample/example.js
117
+ - sample/index.html
118
+ - sample/manifest.yml
119
+ - test/helper.rb
120
+ - test/test_plunk_it.rb
121
+ homepage: http://github.com/delmendo/plunk_it
122
+ licenses:
123
+ - MIT
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ segments:
135
+ - 0
136
+ hash: 2874604884120304833
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 1.8.24
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: Makes it easy to push code to http://plnkr.co
149
+ test_files: []