arcus 0.0.3 → 0.0.4
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.
- data/Rakefile +9 -0
- data/arcus.gemspec +2 -0
- data/bin/arcus +1 -1
- data/lib/arcus.rb +0 -8
- data/lib/arcus/api.rb +50 -11
- data/lib/arcus/cli.rb +1 -1
- data/lib/arcus/version.rb +1 -1
- data/spec/arcus_spec.rb +13 -0
- data/spec/spec_helper.rb +3 -0
- metadata +38 -4
- data/test/test_arcus.rb +0 -19
    
        data/Rakefile
    CHANGED
    
    
    
        data/arcus.gemspec
    CHANGED
    
    | @@ -15,8 +15,10 @@ Gem::Specification.new do |gem| | |
| 15 15 | 
             
              gem.require_paths = ["lib"]
         | 
| 16 16 | 
             
              gem.version       = Arcus::VERSION
         | 
| 17 17 |  | 
| 18 | 
            +
              gem.add_dependency "i18n"
         | 
| 18 19 | 
             
              gem.add_dependency "active_support"
         | 
| 19 20 | 
             
              gem.add_dependency "nori"
         | 
| 20 21 | 
             
              gem.add_dependency "nokogiri"
         | 
| 21 22 | 
             
              gem.add_dependency "cmdparse"
         | 
| 23 | 
            +
              gem.add_dependency "rspec"
         | 
| 22 24 | 
             
            end
         | 
    
        data/bin/arcus
    CHANGED
    
    | @@ -29,7 +29,7 @@ error = case | |
| 29 29 | 
             
                        "Default response must me set in either #{rc_file} or as a environmental variable (ARCUS_DEFAULT_RESPONSE)"
         | 
| 30 30 | 
             
                      when $settings["api_key"] && !$settings["api_secret"]
         | 
| 31 31 | 
             
                        "API Secret must be set when using an API Key"
         | 
| 32 | 
            -
                      when $settings["api_secret"] &&  | 
| 32 | 
            +
                      when $settings["api_secret"] && !$settings["api_key"]
         | 
| 33 33 | 
             
                        "API Key must be set when using an API Secret"
         | 
| 34 34 | 
             
                    end
         | 
| 35 35 |  | 
    
        data/lib/arcus.rb
    CHANGED
    
    
    
        data/lib/arcus/api.rb
    CHANGED
    
    | @@ -5,6 +5,9 @@ require 'active_support/core_ext/hash/reverse_merge' | |
| 5 5 | 
             
            require 'nori'
         | 
| 6 6 | 
             
            require 'nokogiri'
         | 
| 7 7 | 
             
            require 'digest/md5'
         | 
| 8 | 
            +
            require 'base64'
         | 
| 9 | 
            +
            require 'cgi'
         | 
| 10 | 
            +
            require 'openssl'
         | 
| 8 11 | 
             
            require 'logger'
         | 
| 9 12 | 
             
            require 'json'
         | 
| 10 13 | 
             
            require 'arcus/helpers'
         | 
| @@ -46,15 +49,43 @@ module Arcus | |
| 46 49 | 
             
                end
         | 
| 47 50 |  | 
| 48 51 | 
             
                class Request
         | 
| 49 | 
            -
                  attr_accessor :command_name, :params, :api_uri, :callbacks
         | 
| 52 | 
            +
                  attr_accessor :command_name, :params, :api_uri, :callbacks, :api_key, :api_secret
         | 
| 50 53 |  | 
| 51 | 
            -
                  def initialize(command_name, params,  | 
| 54 | 
            +
                  def initialize(command_name, params, callbacks)
         | 
| 52 55 | 
             
                    @command_name = command_name
         | 
| 53 56 | 
             
                    @params = params
         | 
| 54 | 
            -
                    @api_uri = api_uri
         | 
| 57 | 
            +
                    @api_uri = Api.settings.api_uri
         | 
| 58 | 
            +
                    @api_key = Api.settings.api_key
         | 
| 59 | 
            +
                    @api_secret = Api.settings.api_secret
         | 
| 55 60 | 
             
                    @callbacks = callbacks
         | 
| 56 61 | 
             
                  end
         | 
| 57 62 |  | 
| 63 | 
            +
                  def generate_signature(params, api_secret)
         | 
| 64 | 
            +
                    sorted_params = params.map { |k, v| [k, CGI.escape(v.to_s).gsub('+', '%20').downcase] }.sort_by { |key, value| key.to_s }
         | 
| 65 | 
            +
                    data = parameterize(sorted_params, false).downcase
         | 
| 66 | 
            +
                    hash = OpenSSL::HMAC.digest('sha1', api_secret, data)
         | 
| 67 | 
            +
                    Base64.encode64(hash).chomp
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  def parameterize(params, escape=true)
         | 
| 71 | 
            +
                    params = params.collect do |k, v|
         | 
| 72 | 
            +
                      if escape
         | 
| 73 | 
            +
                        "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
         | 
| 74 | 
            +
                      else
         | 
| 75 | 
            +
                        "#{k}=#{v}"
         | 
| 76 | 
            +
                      end
         | 
| 77 | 
            +
                    end
         | 
| 78 | 
            +
                    params.join('&')
         | 
| 79 | 
            +
                  end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                  def generate_params_str(params, api_key = nil, api_secret = nil)
         | 
| 82 | 
            +
                    if api_key && api_secret
         | 
| 83 | 
            +
                      params[:apiKey] = @api_key
         | 
| 84 | 
            +
                      params[:signature] = generate_signature(params, api_secret)
         | 
| 85 | 
            +
                    end
         | 
| 86 | 
            +
                    parameterize(params)
         | 
| 87 | 
            +
                  end
         | 
| 88 | 
            +
             | 
| 58 89 | 
             
                  def fetch(response_type = :object)
         | 
| 59 90 | 
             
                    @params[:response] =
         | 
| 60 91 | 
             
                        case response_type
         | 
| @@ -65,8 +96,14 @@ module Arcus | |
| 65 96 | 
             
                        end
         | 
| 66 97 | 
             
                    http = Net::HTTP.new(@api_uri.host, @api_uri.port)
         | 
| 67 98 | 
             
                    http.read_timeout = 5
         | 
| 68 | 
            -
                    http.open_timeout =  | 
| 69 | 
            -
             | 
| 99 | 
            +
                    http.open_timeout = 5
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                    if @api_uri.scheme == "https"
         | 
| 102 | 
            +
                      http.use_ssl = true
         | 
| 103 | 
            +
                      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         | 
| 104 | 
            +
                    end
         | 
| 105 | 
            +
                    params = @params.merge({:command => @command_name})
         | 
| 106 | 
            +
                    req_url = @api_uri.path + "?" + generate_params_str(params, @api_key, @api_secret)
         | 
| 70 107 | 
             
                    Arcus.log.debug { "Sending: #{req_url}" } if Api.settings.verbose
         | 
| 71 108 | 
             
                    response = begin
         | 
| 72 109 | 
             
                      http.get(req_url)
         | 
| @@ -249,16 +286,18 @@ module Arcus | |
| 249 286 |  | 
| 250 287 | 
             
                          def prepare(params = {}, callbacks = {})
         | 
| 251 288 | 
             
                            params[:response] ||= Api.settings.default_response
         | 
| 252 | 
            -
                            Request.new(self.name, params,  | 
| 289 | 
            +
                            Request.new(self.name, params, callbacks)
         | 
| 253 290 | 
             
                          end
         | 
| 254 291 | 
             
                        end
         | 
| 255 292 | 
             
                        target_clazz.actions << action_clazz
         | 
| 256 293 |  | 
| 257 | 
            -
                        target_clazz. | 
| 258 | 
            -
                           | 
| 259 | 
            -
             | 
| 260 | 
            -
             | 
| 261 | 
            -
                           | 
| 294 | 
            +
                        target_clazz.instance_eval do
         | 
| 295 | 
            +
                          define_method(action.to_sym) do |params = {}, callbacks = {}|
         | 
| 296 | 
            +
                              action_clazz.new.prepare(params, callbacks)
         | 
| 297 | 
            +
                          end
         | 
| 298 | 
            +
                          define_method("#{action}!".to_sym) do |params = {}, callbacks = {}|
         | 
| 299 | 
            +
                              action_clazz.new.prepare(params, callbacks)
         | 
| 300 | 
            +
                          end
         | 
| 262 301 | 
             
                        end
         | 
| 263 302 | 
             
                      end
         | 
| 264 303 | 
             
                    end
         | 
    
        data/lib/arcus/cli.rb
    CHANGED
    
    | @@ -103,7 +103,7 @@ module Arcus | |
| 103 103 | 
             
                          begin
         | 
| 104 104 | 
             
                            response_type = optional_params[:response] || Api.settings.default_response
         | 
| 105 105 | 
             
                            if a.sync
         | 
| 106 | 
            -
                              result = a.prepare(required_params.merge(optional_params)).fetch
         | 
| 106 | 
            +
                              result = a.new.prepare(required_params.merge(optional_params)).fetch
         | 
| 107 107 | 
             
                              job_id = result["#{a.name.downcase}response"]["jobid"]
         | 
| 108 108 | 
             
                              job_finished = false
         | 
| 109 109 | 
             
                              until job_finished
         | 
    
        data/lib/arcus/version.rb
    CHANGED
    
    
    
        data/spec/arcus_spec.rb
    ADDED
    
    | @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
            require 'rspec/core'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Arcus::Api.configure do |c|
         | 
| 5 | 
            +
               c.api_uri = "http://icloud-staging-api.logicworks.net:8096/client/api"
         | 
| 6 | 
            +
               c.default_response = "json"
         | 
| 7 | 
            +
            end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            include Arcus::Api
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            describe Domain do
         | 
| 12 | 
            +
              pending "Domain test"
         | 
| 13 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: arcus
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.4
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,8 +9,24 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012- | 
| 12 | 
            +
            date: 2012-05-01 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: i18n
         | 
| 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'
         | 
| 14 30 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 31 | 
             
              name: active_support
         | 
| 16 32 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -75,6 +91,22 @@ dependencies: | |
| 75 91 | 
             
                - - ! '>='
         | 
| 76 92 | 
             
                  - !ruby/object:Gem::Version
         | 
| 77 93 | 
             
                    version: '0'
         | 
| 94 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 95 | 
            +
              name: rspec
         | 
| 96 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 97 | 
            +
                none: false
         | 
| 98 | 
            +
                requirements:
         | 
| 99 | 
            +
                - - ! '>='
         | 
| 100 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 101 | 
            +
                    version: '0'
         | 
| 102 | 
            +
              type: :runtime
         | 
| 103 | 
            +
              prerelease: false
         | 
| 104 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 105 | 
            +
                none: false
         | 
| 106 | 
            +
                requirements:
         | 
| 107 | 
            +
                - - ! '>='
         | 
| 108 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 109 | 
            +
                    version: '0'
         | 
| 78 110 | 
             
            description: API and client CLI tool for cloudstack
         | 
| 79 111 | 
             
            email:
         | 
| 80 112 | 
             
            - atistler@gmail.com
         | 
| @@ -98,8 +130,9 @@ files: | |
| 98 130 | 
             
            - lib/arcus/commands.xml
         | 
| 99 131 | 
             
            - lib/arcus/helpers.rb
         | 
| 100 132 | 
             
            - lib/arcus/version.rb
         | 
| 133 | 
            +
            - spec/arcus_spec.rb
         | 
| 134 | 
            +
            - spec/spec_helper.rb
         | 
| 101 135 | 
             
            - test.rb
         | 
| 102 | 
            -
            - test/test_arcus.rb
         | 
| 103 136 | 
             
            homepage: ''
         | 
| 104 137 | 
             
            licenses: []
         | 
| 105 138 | 
             
            post_install_message: 
         | 
| @@ -125,4 +158,5 @@ signing_key: | |
| 125 158 | 
             
            specification_version: 3
         | 
| 126 159 | 
             
            summary: API and client CLI tool for cloudstack
         | 
| 127 160 | 
             
            test_files:
         | 
| 128 | 
            -
            -  | 
| 161 | 
            +
            - spec/arcus_spec.rb
         | 
| 162 | 
            +
            - spec/spec_helper.rb
         | 
    
        data/test/test_arcus.rb
    DELETED
    
    | @@ -1,19 +0,0 @@ | |
| 1 | 
            -
            require 'test/unit'
         | 
| 2 | 
            -
            require 'hola'
         | 
| 3 | 
            -
             | 
| 4 | 
            -
            class HolaTest < Test::Unit::TestCase
         | 
| 5 | 
            -
              def test_english_hello
         | 
| 6 | 
            -
                assert_equal "hello world",
         | 
| 7 | 
            -
                  Hola.hi("english")
         | 
| 8 | 
            -
              end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
              def test_any_hello
         | 
| 11 | 
            -
                assert_equal "hello world",
         | 
| 12 | 
            -
                  Hola.hi("ruby")
         | 
| 13 | 
            -
              end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
              def test_spanish_hello
         | 
| 16 | 
            -
                assert_equal "hola mundo",
         | 
| 17 | 
            -
                  Hola.hi("spanish")
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
            end
         |