robocase_shipit 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 23f7a3be8fb9f22ccedf414910ce1a83fb5bda41
4
+ data.tar.gz: d9f111ffc4dd07c4af27d8a850ac1be63aa00f39
5
+ SHA512:
6
+ metadata.gz: 9fb629956339da2f6ae520d317b1b9618a33ea723c96e045a7c59ca4778823cf64ce00ad4eacfe6dbedd163d53461e4ac84c7e82313f589012b74a610f3dedb5
7
+ data.tar.gz: ede9eb5804f015386ecc8b961c11a71f2b10db18d520732277040de80dc3f3635a7f8d8c34e54f51da7e9f65a34fa1b8179153e3e9db53670ff1a30b20752416
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in robocase_shipit.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Robots and Pencils
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.
@@ -0,0 +1,37 @@
1
+ # RobocaseShipit
2
+
3
+ SHIP IT! To roboclient
4
+
5
+ ## Installation
6
+
7
+ Install yourself a little shipping magic.
8
+
9
+ ```sh
10
+ gem install robocase_shipit
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ We are expecting that somewhere you have a ROBOCASE_UUID and a ROBOCASE_TOKEN in your ENV.
16
+
17
+ Then you just
18
+
19
+ ```sh
20
+ shipit path_to_file
21
+ ```
22
+
23
+ If they are not in your path, then you need to set them with the command
24
+
25
+ ```sh
26
+ ROBOCASE_UUID="XXXX-XXX-XXXX" ROBOCASE_TOKEN="1337DEADBEEF1337" shipit path_to_file
27
+ ```
28
+
29
+ If you are testing you should also set ```ROBOCASE_URL="http://robocase.dev/api/v1"``` when you run the command
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/[my-github-username]/robocase_shipit/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "robocase_shipit"
4
+ require 'colorize'
5
+
6
+ args = ARGV.dup
7
+ ARGV.clear
8
+ file_path = args.shift.strip rescue nil
9
+
10
+ if ENV['ROBOCASE_UUID'] && ENV['ROBOCASE_TOKEN'] && file_path
11
+ api = RobocaseShipit::API.new(ENV['ROBOCASE_UUID'], ENV['ROBOCASE_TOKEN'])
12
+ api.upload(file_path)
13
+ else
14
+ puts "USAGE:".colorize(:green)
15
+ puts " ROBOCASE_UUID=\"UUID\" ROBOCASE_TOKEN=\"TOKEN\" shipit ./path/to/file".colorize(:light_blue)
16
+ puts "or if you've set ROBOCASE_UUID and ROBOCASE_TOKEN as ENV vars then you can just"
17
+ puts " shipit ./path/to/file".colorize(:light_blue)
18
+ puts ""
19
+ puts "Remember that your UUID and TOKEN are application and user specific.".colorize(:green)
20
+ puts ""
21
+ end
@@ -0,0 +1,6 @@
1
+ require "robocase_shipit/version"
2
+ require "robocase_shipit/api"
3
+
4
+ module RobocaseShipit
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,92 @@
1
+ require 'rest_client'
2
+ require 'colorize'
3
+
4
+ module RobocaseShipit
5
+ class API
6
+ def self.robocase_url
7
+ ENV['ROBOCASE_URL'] ? ENV['ROBOCASE_URL'] : 'https://www.robocase.io/api/v1'
8
+ end
9
+
10
+ def initialize(key, token)
11
+ @key = key
12
+ @token = token
13
+ end
14
+
15
+ def upload(filename)
16
+ if File.exists?(filename)
17
+ response = self.obtain_upload_url(filename)
18
+ return if response.nil?
19
+ item_details = JSON.parse(response)
20
+
21
+ puts "Uploading new version of #{item_details['item']}".colorize(:green)
22
+ response = self.upload_version(item_details, filename)
23
+ return if response.nil?
24
+
25
+ puts "Confirming upload of #{item_details['item']}".colorize(:green)
26
+ metadata = self.confirm_upload(item_details['uuid'], filename)
27
+ return if metadata.nil?
28
+
29
+ puts "Verifying metadata".colorize(:green)
30
+ if self.check_metadata(metadata, filename)
31
+ puts "Success".colorize(:green)
32
+ else
33
+ puts "ERROR!".colorize(:red)
34
+ end
35
+ else
36
+ puts "ERROR: The file that you've specified does not exist".colorize(:red)
37
+ end
38
+ end
39
+
40
+ def obtain_upload_url(filename)
41
+ options = { filename: filename}
42
+ begin
43
+ response = RestClient.post(RobocaseShipit::API::robocase_url + "/items/version", options, {"X-Robocase-UUID" => @key, "X-RoboCase-Token" => @token})
44
+ rescue Exception => e
45
+ puts e.message.colorize(:red)
46
+ response = nil
47
+ end
48
+ end
49
+
50
+ def upload_version(options, file)
51
+ begin
52
+ response = RestClient.post options['url'], options['fields'].merge(file: File.new("./#{file}", 'rb')), {}
53
+ rescue
54
+ puts e.message.colorize(:red)
55
+ response = nil
56
+ end
57
+ end
58
+
59
+ def confirm_upload(uuid, filename)
60
+ options = { uuid: uuid }
61
+ response = RestClient.put(RobocaseShipit::API::robocase_url + "/items/version", options, {"X-RoboCase-UUID" => @key, "X-RoboCase-Token" => @token})
62
+ metadata = JSON.parse(response)
63
+ end
64
+
65
+ def check_metadata(metadata, filename)
66
+ s3_size = metadata['content_length']
67
+ s3_md5 = metadata['etag']
68
+
69
+ if s3_size && s3_md5
70
+ size = File.size filename
71
+ if size == s3_size
72
+ puts "#{s3_size} matches #{size}".colorize(:green)
73
+ else
74
+ puts "ERROR: #{s3_size} did not match #{size}".colorize(:red)
75
+ return false
76
+ end
77
+
78
+ md5 = Digest::MD5.file(filename).hexdigest
79
+ if "\"#{md5}\"" == s3_md5
80
+ puts "#{s3_md5} matches \"#{md5}\"".colorize(:green)
81
+ else
82
+ puts "ERROR: #{s3_md5} did not match \"#{md5}\"".colorize(:red)
83
+ return false
84
+ end
85
+ true
86
+ else
87
+ puts "ERROR: uploaded file did not match!"
88
+ false
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,3 @@
1
+ module RobocaseShipit
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'robocase_shipit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "robocase_shipit"
8
+ spec.version = RobocaseShipit::VERSION
9
+ spec.authors = ["Mark Madsen", "Robots and Pencils"]
10
+ spec.email = ["gems@robotsandpencils.com"]
11
+ spec.summary = "SHIPIT!"
12
+ spec.description = ""
13
+ spec.homepage = "https://www.robocase.io"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ["shipit"]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "rest-client"
22
+ spec.add_runtime_dependency "colorize"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: robocase_shipit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mark Madsen
8
+ - Robots and Pencils
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-10-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: colorize
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.7'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.7'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.0'
70
+ description: ''
71
+ email:
72
+ - gems@robotsandpencils.com
73
+ executables:
74
+ - shipit
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/shipit
84
+ - lib/robocase_shipit.rb
85
+ - lib/robocase_shipit/api.rb
86
+ - lib/robocase_shipit/version.rb
87
+ - robocase_shipit.gemspec
88
+ homepage: https://www.robocase.io
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: SHIPIT!
112
+ test_files: []