racked 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.1"
12
+ gem "rcov", ">= 0"
13
+ end
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.1)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+ rcov (0.9.9)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.5.1)
19
+ rcov
20
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Noto Modungwa
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,37 @@
1
+ = racked
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to racked
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Noto Modungwa. See LICENSE.txt for
18
+ further details.
19
+
20
+ == Directions
21
+
22
+ #gem install racked
23
+
24
+ In your config file e.g "mailapi.yml"
25
+ server: 'api.emailsrvr.com'
26
+ version_prefix: '/v0'
27
+ user_key: 'xxxxxxx'
28
+ secret_hash: 'xxxxxxx
29
+
30
+ In your initializer or before you call the API
31
+ require 'yaml' #depending on your situation
32
+ MAIL_CFG = YAML::load(File.read('path_to/mailapi.yml'))
33
+
34
+ == Usage:
35
+
36
+ api = Racked.new
37
+ mailboxes = api.get_mailmoxes # => [{"name"=>"tomthumb", "displayName"=>"Tom Thumb"}, {"name"=>"dicktracy", "displayName"=>"Dick Tracy"}]
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "racked"
16
+ gem.homepage = "http://github.com/NoTiTo/racked"
17
+ gem.license = "MIT"
18
+ gem.summary = "Rackspace mailbox management API "
19
+ gem.description = "Allows you to manage your rackspace hosted mailboxes, eg. create a new mailbox."
20
+ gem.email = "notomodungwa@gmail.com"
21
+ gem.authors = ["Noto Modungwa"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "racked #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,72 @@
1
+ # coding: utf-8
2
+ require 'json'
3
+ require './lib/racked/server.rb'
4
+
5
+ class Mailbox
6
+
7
+ def initialize(attributes)
8
+ @attributes = attributes #JSON.parse(json)
9
+ end
10
+
11
+ def method_missing(method, *args)
12
+ #x = method.to_s.camelize(:lower)
13
+ x = method.to_s
14
+    #return @attributes[access_key] if(@attributes.keys.include?(access_key))
15
+    if(@attributes.keys.include?(x))
16
+      @attributes[x]
17
+    else
18
+      super
19
+    end
20
+ end
21
+
22
+ end
23
+
24
+ class Racked
25
+ #include Singleton
26
+
27
+ def initialize
28
+ #read config file
29
+
30
+ @server = Server.new(MAIL_CFG["server"], MAIL_CFG["version_prefix"], MAIL_CFG["user_key"], MAIL_CFG["secret_hash"])
31
+ @server.xml_format
32
+ end
33
+
34
+ def get_mailboxes
35
+ #get customer list
36
+ response = @server.get '/customers/856863/domains/econetmail.com/rs/mailboxes', @server.json_format
37
+ puts response.inspect
38
+ # puts response['x-error-message']
39
+ # puts response.body
40
+ response = JSON.parse(response.body )
41
+ # puts response.inspect
42
+ #TO DO: error checking
43
+ # returning [] do |mailboxes|
44
+ # response["rsMailboxes"].each {|c| mailboxes << Mailbox.new(c) }
45
+ # end
46
+ mailboxes = []
47
+ response["rsMailboxes"].each do |mailbox|
48
+ mailboxes << Mailbox.new(mailbox)
49
+ end
50
+ end
51
+
52
+ def create_mailbox
53
+ #create a customer mailbox
54
+
55
+ end
56
+
57
+ end
58
+
59
+ # api = Racked.instance
60
+ #
61
+ # api.get_customers
62
+ #
63
+ # server = Server.new
64
+ #
65
+ # response = server.get '/customers', server.xml_format
66
+ #
67
+ # #fields = Hash['serviceType' => 'exchange', 'exchangeMaxNumMailboxes' => '4']
68
+ # #response = server.post '/customers/me/domains/newdomain.com', fields
69
+ #
70
+ # puts response.code
71
+ # puts response['x-error-message']
72
+ # puts response.body
@@ -0,0 +1,101 @@
1
+ require 'test/unit/assertions'
2
+ require 'net/http'
3
+ require 'date'
4
+ require 'date/format'
5
+ require 'digest/sha1'
6
+ require 'base64'
7
+ require 'time'
8
+
9
+ class Server
10
+ include Test::Unit::Assertions
11
+
12
+ def initialize(server='api.emailsrvr.com', version_prefix='/v0', user_key='xxxxxxxxxxxxxxxxxxxx', secret_hash='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
13
+ @server = server
14
+ @version_prefix = version_prefix
15
+ @user_key = user_key
16
+ @secret_hash = secret_hash
17
+ end
18
+
19
+ # Response Type Enums
20
+
21
+ def xml_format
22
+ 'text/xml'
23
+ end
24
+
25
+ def json_format
26
+ 'application/json'
27
+ end
28
+
29
+ #
30
+ # HTTP Request Verbs
31
+ #
32
+ def get(url_string, format)
33
+ uri = full_uri(url_string)
34
+ headers = prepared_headers
35
+ headers['Accept'] = format
36
+ request = Net::HTTP::Get.new(request_uri(uri), headers)
37
+ http_response = make_request request, uri
38
+ end
39
+
40
+ def delete(url_string)
41
+ uri = full_uri(url_string)
42
+ request = Net::HTTP::Delete.new(request_uri(uri), prepared_headers)
43
+ http_response = make_request request, uri
44
+ end
45
+
46
+ def put(url_string, fields_hash)
47
+ uri = full_uri(url_string)
48
+ request = Net::HTTP::Put.new(request_uri(uri), prepared_headers)
49
+ request.set_form_data(fields_hash)
50
+ http_response = make_request request, uri
51
+ end
52
+
53
+ def post(url_string, fields_hash)
54
+ uri = full_uri(url_string)
55
+ request = Net::HTTP::Post.new(request_uri(uri), prepared_headers)
56
+ request.set_form_data(fields_hash)
57
+ http_response = make_request request, uri
58
+ end
59
+
60
+ #
61
+ # HTTP Request Helpers
62
+ #
63
+ def make_request request, uri
64
+ response = Net::HTTP::start(uri.host, uri.port) do |http|
65
+ http.request request
66
+ end
67
+
68
+ response
69
+ end
70
+
71
+ def full_uri url_string
72
+ URI.parse('http://' + @server + @version_prefix + url_string)
73
+ end
74
+
75
+ def request_uri uri
76
+ request = uri.path
77
+ if ! uri.query.nil?
78
+ request = request + '?' + uri.query
79
+ end
80
+ request
81
+ end
82
+
83
+ def prepared_headers
84
+ headers = Hash.new
85
+ headers.merge! headers_auth_creds(@user_key, @secret_hash)
86
+ headers['Accept'] = xml_format
87
+ headers
88
+ end
89
+
90
+ def headers_auth_creds apiKey, secretKey
91
+ userAgent = 'Ruby Test Client'
92
+ timestamp = DateTime.now.strftime('%Y%m%d%H%M%S')
93
+
94
+ data_to_sign = apiKey + userAgent + timestamp + secretKey
95
+
96
+ hash = Base64.encode64(Digest::SHA1.digest(data_to_sign))
97
+ signature = apiKey + ":" + timestamp + ":" + hash
98
+
99
+ headers = Hash['User-Agent' => userAgent, 'X-Api-Signature' => signature]
100
+ end
101
+ end
@@ -0,0 +1,65 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{racked}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Noto Modungwa"]
12
+ s.date = %q{2010-12-07}
13
+ s.description = %q{Allows you to manage your rackspace hosted mailboxes, eg. create a new mailbox.}
14
+ s.email = %q{notomodungwa@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/racked.rb",
28
+ "lib/racked/server.rb",
29
+ "racked.gemspec",
30
+ "test/helper.rb",
31
+ "test/test_racked.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/NoTiTo/racked}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.7}
37
+ s.summary = %q{Rackspace mailbox management API}
38
+ s.test_files = [
39
+ "test/helper.rb",
40
+ "test/test_racked.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
56
+ s.add_dependency(%q<rcov>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ end
64
+ end
65
+
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'racked'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRacked < 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,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: racked
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Noto Modungwa
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-07 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: shoulda
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 1
42
+ - 0
43
+ - 0
44
+ version: 1.0.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 5
58
+ - 1
59
+ version: 1.5.1
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: rcov
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ type: :development
74
+ prerelease: false
75
+ version_requirements: *id004
76
+ description: Allows you to manage your rackspace hosted mailboxes, eg. create a new mailbox.
77
+ email: notomodungwa@gmail.com
78
+ executables: []
79
+
80
+ extensions: []
81
+
82
+ extra_rdoc_files:
83
+ - LICENSE.txt
84
+ - README.rdoc
85
+ files:
86
+ - .document
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ - Rakefile
92
+ - VERSION
93
+ - lib/racked.rb
94
+ - lib/racked/server.rb
95
+ - racked.gemspec
96
+ - test/helper.rb
97
+ - test/test_racked.rb
98
+ has_rdoc: true
99
+ homepage: http://github.com/NoTiTo/racked
100
+ licenses:
101
+ - MIT
102
+ post_install_message:
103
+ rdoc_options: []
104
+
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 78057969
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirements: []
125
+
126
+ rubyforge_project:
127
+ rubygems_version: 1.3.7
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: Rackspace mailbox management API
131
+ test_files:
132
+ - test/helper.rb
133
+ - test/test_racked.rb