rackspace-apps 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -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 Carl Hicks
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.
@@ -0,0 +1,17 @@
1
+ = rackspace-apps
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (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)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Carl Hicks. See LICENSE for details.
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rackspace-apps"
8
+ gem.summary = %Q{REST Bindings for Rackspace Email and Apps API}
9
+ gem.description = %Q{REST Bindings for Rackspace Email and Apps API}
10
+ gem.email = "carl.hicks@gmail.com"
11
+ gem.homepage = "http://github.com/chicks/rackspace-apps"
12
+ gem.authors = ["Carl Hicks"]
13
+ gem.add_dependency "json", ">= 0"
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "rackspace-apps #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,146 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'net/http'
4
+ require 'date'
5
+ require 'date/format'
6
+ require 'digest/sha1'
7
+ require 'base64'
8
+ require 'time'
9
+ require 'rubygems'
10
+ require 'json'
11
+
12
+ module Rackspace
13
+
14
+ class Client
15
+
16
+ attr :connection, true
17
+
18
+ def initialize(user_key, secret_hash, opts={})
19
+ options = {
20
+ :server => 'api.emailsrvr.com',
21
+ :version_prefix => '/v0'
22
+ }.merge! opts
23
+ @server = options[:server]
24
+ @version_prefix = options[:version_prefix]
25
+ @user_key = user_key
26
+ @secret_hash = secret_hash
27
+ @connection = false
28
+ end
29
+
30
+ # Response Type Enums
31
+
32
+ def xml_format
33
+ 'text/xml'
34
+ end
35
+
36
+ def json_format
37
+ 'application/json'
38
+ end
39
+
40
+ #
41
+ # HTTP Request Verbs
42
+ #
43
+ def get(url_string, format)
44
+ uri = full_uri(url_string)
45
+ headers = prepared_headers
46
+ headers['Accept'] = format
47
+ request = Net::HTTP::Get.new(request_uri(uri), headers)
48
+ http_response = make_request request, uri
49
+ end
50
+
51
+ def delete(url_string)
52
+ uri = full_uri(url_string)
53
+ request = Net::HTTP::Delete.new(request_uri(uri), prepared_headers)
54
+ http_response = make_request request, uri
55
+ end
56
+
57
+ def put(url_string, fields_hash)
58
+ uri = full_uri(url_string)
59
+ request = Net::HTTP::Put.new(request_uri(uri), prepared_headers)
60
+ request.set_form_data(fields_hash)
61
+ http_response = make_request request, uri
62
+ end
63
+
64
+ def post(url_string, fields_hash)
65
+ uri = full_uri(url_string)
66
+ request = Net::HTTP::Post.new(request_uri(uri), prepared_headers)
67
+ request.set_form_data(fields_hash)
68
+ http_response = make_request request, uri
69
+ end
70
+
71
+ #
72
+ # HTTP Request Helpers
73
+ #
74
+ def make_request request, uri
75
+ connect! unless connected?
76
+ response = @connection.request(request)
77
+
78
+ case response
79
+ when Net::HTTPOK
80
+ if response.body.length > 0
81
+ return JSON.parse(response.body)
82
+ else
83
+ return true
84
+ end
85
+ when Net::HTTPForbidden
86
+ if response['x-error-message'] =~ /Exceeded request limits/
87
+ sleep 5
88
+ make_request request, uri
89
+ else
90
+ raise RuntimeError, "HTTP Forbidden - Are you logged in?"
91
+ end
92
+ else
93
+ raise RuntimeError, "Can't handle response #{response['x-error-message']}"
94
+ end
95
+ end
96
+
97
+ def full_uri(url_string)
98
+ URI.parse('http://' + @server + @version_prefix + url_string)
99
+ end
100
+
101
+ def request_uri(uri)
102
+ request = uri.path
103
+ if ! uri.query.nil?
104
+ request = request + '?' + uri.query
105
+ end
106
+ request
107
+ end
108
+
109
+ def prepared_headers
110
+ headers = Hash.new
111
+ headers.merge! headers_auth_creds(@user_key, @secret_hash)
112
+ headers['Accept'] = xml_format
113
+ headers
114
+ end
115
+
116
+ def headers_auth_creds(apiKey, secretKey)
117
+ userAgent = 'Ruby Test Client'
118
+ timestamp = DateTime.now.strftime('%Y%m%d%H%M%S')
119
+
120
+ data_to_sign = apiKey + userAgent + timestamp + secretKey
121
+
122
+ hash = Base64.encode64(Digest::SHA1.digest(data_to_sign))
123
+ signature = apiKey + ":" + timestamp + ":" + hash
124
+
125
+ headers = Hash['User-Agent' => userAgent, 'X-Api-Signature' => signature]
126
+ end
127
+
128
+ # Check to see if we have an HTTP/S Connection
129
+ def connected?
130
+ return false unless @connection
131
+ return false unless @connection.started?
132
+ true
133
+ end
134
+
135
+ # Connect to the remote system.
136
+ def connect!
137
+ @connection = Net::HTTP.new(@server, 80)
138
+ if @ssl
139
+ @connection.use_ssl = true
140
+ @connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
141
+ end
142
+ @connection.start
143
+ end
144
+
145
+ end
146
+ end
@@ -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 'rackspace-apps'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRackspaceApps < 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,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rackspace-apps
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Carl Hicks
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-26 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: json
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: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: thoughtbot-shoulda
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: :development
48
+ version_requirements: *id002
49
+ description: REST Bindings for Rackspace Email and Apps API
50
+ email: carl.hicks@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - LICENSE
57
+ - README.rdoc
58
+ files:
59
+ - .document
60
+ - .gitignore
61
+ - LICENSE
62
+ - README.rdoc
63
+ - Rakefile
64
+ - VERSION
65
+ - lib/rackspace-apps.rb
66
+ - test/helper.rb
67
+ - test/test_rackspace-apps.rb
68
+ has_rdoc: true
69
+ homepage: http://github.com/chicks/rackspace-apps
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options:
74
+ - --charset=UTF-8
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.3.7
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: REST Bindings for Rackspace Email and Apps API
102
+ test_files:
103
+ - test/helper.rb
104
+ - test/test_rackspace-apps.rb