Class: Trigonal
- Inherits:
-
Object
- Object
- Trigonal
- Includes:
- Sys
- Defined in:
- lib/trigonal/errors.rb,
lib/trigonal/trigonal.rb
Defined Under Namespace
Classes: InvalidCredentialsError, OptionsError, UnknownServerError
Constant Summary collapse
- SERVER_PROTOCOL =
'http'
- SERVER_HOST =
'trigonal.herokuapp.com'
- SERVER_PORT =
'80'
- SERVER_PATH =
'/api/manifests.json'
- LIVE_ENVIRONMENTS =
%w[stage staging production master]
Instance Method Summary collapse
- #appname(val = nil) ⇒ Object
- #environment(val = nil) ⇒ Object
- #get_appname ⇒ Object
- #get_environment ⇒ Object
- #get_gems ⇒ Object
- #get_gems_from_host ⇒ Object
- #get_host_name ⇒ Object
- #get_name ⇒ Object
- #host_name(val = nil) ⇒ Object
- #host_ruby ⇒ Object
- #host_system_software ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Trigonal
constructor
A new instance of Trigonal.
- #live_environment? ⇒ Boolean
- #name(val = nil) ⇒ Object
- #post_manifest(options = {}) ⇒ Object
- #server_url ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Trigonal
Returns a new instance of Trigonal.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/trigonal/trigonal.rb', line 17 def initialize( = {}, &block) raise OptionsError unless [:email] raise OptionsError unless ([:password] || [:key]) @email = [:email] @password = [:password] @key = [:key] yield self if block_given? end |
Instance Method Details
#appname(val = nil) ⇒ Object
109 110 111 |
# File 'lib/trigonal/trigonal.rb', line 109 def appname(val=nil) val ? @appname=val : @appname end |
#environment(val = nil) ⇒ Object
105 106 107 |
# File 'lib/trigonal/trigonal.rb', line 105 def environment(val=nil) val ? @environment=val : @environment end |
#get_appname ⇒ Object
72 73 74 |
# File 'lib/trigonal/trigonal.rb', line 72 def get_appname @appname end |
#get_environment ⇒ Object
80 81 82 |
# File 'lib/trigonal/trigonal.rb', line 80 def get_environment @environment ||= "development" end |
#get_gems ⇒ Object
84 85 86 |
# File 'lib/trigonal/trigonal.rb', line 84 def get_gems @gems || get_gems_from_host end |
#get_gems_from_host ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/trigonal/trigonal.rb', line 88 def get_gems_from_host Gem::Specification.map do |specification| { :name => specification.name, :version => specification.version.to_s } end end |
#get_host_name ⇒ Object
68 69 70 |
# File 'lib/trigonal/trigonal.rb', line 68 def get_host_name @host_name ||= Host.hostname end |
#get_name ⇒ Object
76 77 78 |
# File 'lib/trigonal/trigonal.rb', line 76 def get_name @name end |
#host_name(val = nil) ⇒ Object
113 114 115 |
# File 'lib/trigonal/trigonal.rb', line 113 def host_name(val=nil) val ? @host_name=val : @host_name end |
#host_ruby ⇒ Object
64 65 66 |
# File 'lib/trigonal/trigonal.rb', line 64 def host_ruby @host_ruby ||= RUBY_DESCRIPTION end |
#host_system_software ⇒ Object
60 61 62 |
# File 'lib/trigonal/trigonal.rb', line 60 def host_system_software @host_system_software ||= Uname.uname.version end |
#live_environment? ⇒ Boolean
97 98 99 |
# File 'lib/trigonal/trigonal.rb', line 97 def live_environment? LIVE_ENVIRONMENTS.include?(get_environment) end |
#name(val = nil) ⇒ Object
101 102 103 |
# File 'lib/trigonal/trigonal.rb', line 101 def name(val=nil) val ? @name=val : @name end |
#post_manifest(options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/trigonal/trigonal.rb', line 33 def post_manifest( = {}) return unless (live_environment? || [:force]) response = HTTParty.post(server_url, :body => MultiJson.dump({ :email => @email, :key => @key, :password => @password, :system => host_system_software, :ruby => host_ruby, :hostname => get_host_name, :name => get_name, :appname => get_appname, :environment => get_environment, :gems => get_gems }), :headers => { 'Content-Type' => 'application/json' } ).response case response.code when /^2\d+/ return true when "401" raise Trigonal::InvalidCredentialsError, "Email address and password or key was not accepted" else raise Trigonal::UnknownServerError, "Unknown upstream server (code #{response.code}) occured" end end |
#server_url ⇒ Object
29 30 31 |
# File 'lib/trigonal/trigonal.rb', line 29 def server_url "#{SERVER_PROTOCOL}://#{SERVER_HOST}:#{SERVER_PORT}#{SERVER_PATH}" end |