sunrise 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
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Logan Koester
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.rdoc ADDED
@@ -0,0 +1,36 @@
1
+ = Sunrise Ruby Library & Command-Line Uploader
2
+
3
+ This Ruby gem aims to provide a reference implementation for developers working with the
4
+ Sunrise API. It also includes a handy command-line tool for uploading files to your account.
5
+
6
+ == Getting Started
7
+ First, install the gem (assuming you already have Ruby and Rubygems on your system)
8
+ gem install sunrise
9
+
10
+ Now you'll want to create a configuration file with your Sunrise account details.
11
+
12
+ This will ask you for your login, password, and if you have more than one team, which
13
+ to use as the default.
14
+ sunrise setup
15
+
16
+ Now that's taken care of, uploading a file is as easy as
17
+ sunrise upload yourfile.jpg "My File"
18
+
19
+ Full documentation can be accessed with
20
+ sunrise --help
21
+
22
+ Enjoy!
23
+
24
+ == Note on Patches/Pull Requests
25
+
26
+ * Fork the project.
27
+ * Make your feature addition or bug fix.
28
+ * Add tests for it. This is important so I don't break it in a
29
+ future version unintentionally.
30
+ * Commit, do not mess with rakefile, version, or history.
31
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
32
+ * Send me a pull request. Bonus points for topic branches.
33
+
34
+ == Copyright
35
+
36
+ Copyright (c) 2010 Logan Koester. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "sunrise"
8
+ gem.summary = %Q{Command-line uploader for Sunrise (http://sunrisehq.com)}
9
+ gem.description = %Q{Ruby library for the Sunrise API and command-line upload tool}
10
+ gem.email = "logan@logankoester.com"
11
+ gem.homepage = "http://github.com/logankoester/sunrise"
12
+ gem.authors = ["Logan Koester"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.add_dependency "commander"
15
+ gem.add_dependency "rest-client"
16
+ gem.executables = ["sunrise"]
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "sunrise #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/sunrise ADDED
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'yaml'
4
+ require 'json'
5
+ require 'rubygems'
6
+ require 'commander/import'
7
+ require 'lib/sunrise.rb'
8
+
9
+ CONFIG_FNAME = "#{ENV['HOME']}/.sunrisehq"
10
+ DEVCONFIG_FNAME = "#{ENV['HOME']}/.sunrisehq-dev"
11
+
12
+ # Load settings from the config and developer config files,
13
+ # and apply current overrides from options
14
+ def settings(options = nil)
15
+ if File.exists?(CONFIG_FNAME)
16
+ settings = YAML.load( File.read(CONFIG_FNAME) )
17
+ else
18
+ settings = {}
19
+ end
20
+ if options
21
+ # Override default settings with command-line options
22
+ settings.merge!({ 'login' => options['login'] }) if options['login']
23
+ settings.merge!({ 'password' => options['password'] }) if options['password']
24
+ settings.merge!({ 'default_team' => options['team'] }) if options['team']
25
+ end
26
+ if File.exists?(DEVCONFIG_FNAME)
27
+ # Merge in developer settings as well
28
+ settings.merge!( YAML.load( File.read(DEVCONFIG_FNAME) ) )
29
+ else
30
+ # Set default (production) host/port
31
+ settings.merge!({ 'host' => 'sunrisehq.com', 'port' => 80 })
32
+ end
33
+ settings
34
+ end
35
+
36
+ # Get a properly configured sunrise::Client
37
+ def setup_sunrise_client(options = nil)
38
+ Sunrise::Client.new(settings(options)['login'], settings(options)['password'], settings(options)['host'], settings(options)['port'])
39
+ end
40
+
41
+ program :name, 'Sunrise Uploader'
42
+ program :version, '0.0.1'
43
+ program :description, 'Command-line uploader for Sunrise (http://sunrisehq.com)'
44
+ global_option('--verbose', 'Display non-critical status information') { $verbose = true }
45
+ global_option('--growl', 'Use growl notifications (Mac OS X only)') { $growl = true }
46
+
47
+ if File.exists? CONFIG_FNAME
48
+ default_command :upload
49
+ else
50
+ default_command :setup
51
+ end
52
+
53
+ command :setup do |c|
54
+ c.syntax = "sunrise setup"
55
+ c.description = "Configure your Sunrise account (interactive)"
56
+ c.action do |args, options|
57
+ say "Welcome to Sunrise! Please answer a few questions to setup your account.\n\n" unless File.exists? CONFIG_FNAME
58
+
59
+ @login = ask "SunriseHQ Login (username): "
60
+ @password = password "SunriseHQ Password: ", "*"
61
+
62
+ # Fetch a list of teams from this Sunrise account
63
+ say "\nValidating your credentials...\n"
64
+ sunrise = setup_sunrise_client({'login' => @login, 'password' => @password})
65
+ teams = sunrise.teams
66
+
67
+ # Set a default team to upload to
68
+ @team = (teams.size > 1) ? choose("Choose a default team:", *teams) : teams.first
69
+
70
+ @new_settings = { 'login' => @login, 'password' => @password, 'default_team' => @team }
71
+ File.open(CONFIG_FNAME, 'w') { |f| f << @new_settings.to_yaml }
72
+ say "\nSettings written to #{CONFIG_FNAME}"
73
+ say "You may now begin using Sunrise!"
74
+ end
75
+ end
76
+
77
+ command :upload do |c|
78
+ c.syntax = 'sunrise upload <file> [name]'
79
+ c.description = 'Upload a file to your Sunrise account'
80
+ c.option '--login LOGIN', String, 'Use a different Sunrise account'
81
+ c.option '--password PASSWORD', String, 'Password for your Sunrise account'
82
+ c.option '--team TEAM', String, 'Override the default team'
83
+
84
+ c.action do |args, options|
85
+ if args.first
86
+ @file = File.open(args.first)
87
+
88
+ # Upload the file
89
+ log "Using login '#{settings(options)['login']}'\n" if $verbose
90
+ log "Uploading #{args.first} to team '#{settings(options)['default_team']}'\n" if $verbose
91
+ sunrise = setup_sunrise_client(options)
92
+ sunrise.upload @file, settings(options)['default_team'], args[1]
93
+
94
+ # Parse and display the response
95
+ result = JSON.parse(sunrise.response.body)
96
+ if result['errors']
97
+ result['errors'].each do |error|
98
+ say "#{error[0]}: #{error[1]}"
99
+ end
100
+ say "File was not uploaded"
101
+ notify_error "File was not uploaded" if $growl
102
+ else
103
+ say result['notice'] if $verbose
104
+ notify_ok result['notice'] if $growl
105
+ end
106
+ else
107
+ say "Usage: sunrise upload <file> [name]"
108
+ say "Try sunrise --help for full documentation"
109
+ end
110
+ end
111
+ end
112
+
113
+ command :teams do |c|
114
+ c.syntax = 'sunrise teams'
115
+ c.description = 'List the teams you are a member of'
116
+ c.option '--login LOGIN', String, 'Use a different Sunrise account'
117
+ c.option '--password PASSWORD', String, 'Password for your Sunrise account'
118
+ c.action do |args, options|
119
+ sunrise = setup_sunrise_client(options)
120
+ say sunrise.teams.join("\n")
121
+ end
122
+ end
123
+
124
+ command :developer do |c|
125
+ c.syntax = 'sunrise developer'
126
+ c.description = 'Set special options only relevant to the SunriseHQ Development Team'
127
+ c.action do |args, options|
128
+ @host = ask "SunriseHQ Server Host: "
129
+ @port = ask "SunriseHQ Server Port: "
130
+
131
+ @developer_settings = { 'host' => @host, 'port' => @port }
132
+ File.open(DEVCONFIG_FNAME, 'w') { |f| f << @developer_settings.to_yaml }
133
+ say "\nSettings written to #{DEVCONFIG_FNAME}"
134
+ end
135
+ end
data/lib/sunrise.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+
4
+ module Sunrise
5
+
6
+ class Client
7
+ attr_accessor :login, :password, :response, :host, :port
8
+ def initialize(login, password, host = 'sunrisehq.com', port = '80')
9
+ @login, @password, @host, @port = login, password, host, port
10
+ end
11
+
12
+ def upload(file, team, name = nil)
13
+ name = default_name(file) unless name
14
+ url = "http://#{@login}:#{@password}@#{team}.sunrisehq.local:3000/upload.json"
15
+ @response = RestClient.post url,
16
+ :item => {
17
+ :type => 'Screenshot',
18
+ :image => File.new(file),
19
+ :name => name,
20
+ },
21
+ :content_type => :json,
22
+ :accept => :json
23
+ end
24
+
25
+ # Fetch an array of teams from an account
26
+ def teams
27
+ url = "http://#{@login}:#{@password}@#{@host}:#{@port}/team.json"
28
+ @response = RestClient.get url#, :content_type => :json, :accept => :json
29
+ teams = []
30
+ JSON.parse(@response).each { |team| teams << team['team']['subdomain'] }
31
+ return teams
32
+ end
33
+
34
+ private
35
+ # If no name for an upload is specified, set a default name using the
36
+ # first part of the filename.
37
+ def default_name(file)
38
+ File.basename(file)
39
+ end
40
+ end
41
+
42
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'sunrise'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestSunrise < 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,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sunrise
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Logan Koester
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-15 00:00:00 -04:00
19
+ default_executable: sunrise
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: commander
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rest-client
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ description: Ruby library for the Sunrise API and command-line upload tool
64
+ email: logan@logankoester.com
65
+ executables:
66
+ - sunrise
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - LICENSE
71
+ - README.rdoc
72
+ files:
73
+ - .document
74
+ - .gitignore
75
+ - LICENSE
76
+ - README.rdoc
77
+ - Rakefile
78
+ - VERSION
79
+ - bin/sunrise
80
+ - lib/sunrise.rb
81
+ - test/helper.rb
82
+ - test/test_sunrise.rb
83
+ has_rdoc: true
84
+ homepage: http://github.com/logankoester/sunrise
85
+ licenses: []
86
+
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --charset=UTF-8
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ requirements: []
111
+
112
+ rubyforge_project:
113
+ rubygems_version: 1.3.7
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Command-line uploader for Sunrise (http://sunrisehq.com)
117
+ test_files:
118
+ - test/helper.rb
119
+ - test/test_sunrise.rb