lamed 0.1.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.3.0
data/lamed.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lamed}
8
- s.version = "0.1.3"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Lee Chang"]
12
- s.date = %q{2010-01-19}
12
+ s.date = %q{2010-04-15}
13
13
  s.description = %q{Yet another LaMe Ruby Web Framework}
14
14
  s.email = %q{leetchang@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,6 +25,9 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "lamed.gemspec",
27
27
  "lib/lamed.rb",
28
+ "lib/lamed/aws/authentication.rb",
29
+ "lib/lamed/aws/aws.rb",
30
+ "lib/lamed/aws/sqs.rb",
28
31
  "lib/lamed/controller.rb",
29
32
  "lib/lamed/helper.rb",
30
33
  "lib/lamed/initializer.rb",
@@ -44,10 +47,14 @@ Gem::Specification.new do |s|
44
47
  "spec/examples/ext/views/lamest/bar.mustache",
45
48
  "spec/examples/ext/views/lamest/foo.mustache",
46
49
  "spec/examples/lib/foo_lib.rb",
47
- "spec/helpers_spec.rb",
48
- "spec/initializer_spec.rb",
49
- "spec/lame_spec.rb",
50
- "spec/object_loader_spec.rb",
50
+ "spec/lamed/aws/authentication_spec.rb",
51
+ "spec/lamed/aws/spec.rb",
52
+ "spec/lamed/aws/sqs_spec.rb",
53
+ "spec/lamed/controller_spec.rb",
54
+ "spec/lamed/helper_spec.rb",
55
+ "spec/lamed/initializer_spec.rb",
56
+ "spec/lamed/model_spec.rb",
57
+ "spec/lamed/object_loader_spec.rb",
51
58
  "spec/spec.opts",
52
59
  "spec/spec_helper.rb"
53
60
  ]
@@ -63,10 +70,14 @@ Gem::Specification.new do |s|
63
70
  "spec/examples/ext/models/bar_model.rb",
64
71
  "spec/examples/ext/models/foo_model.rb",
65
72
  "spec/examples/lib/foo_lib.rb",
66
- "spec/helpers_spec.rb",
67
- "spec/initializer_spec.rb",
68
- "spec/lame_spec.rb",
69
- "spec/object_loader_spec.rb",
73
+ "spec/lamed/aws/authentication_spec.rb",
74
+ "spec/lamed/aws/spec.rb",
75
+ "spec/lamed/aws/sqs_spec.rb",
76
+ "spec/lamed/controller_spec.rb",
77
+ "spec/lamed/helper_spec.rb",
78
+ "spec/lamed/initializer_spec.rb",
79
+ "spec/lamed/model_spec.rb",
80
+ "spec/lamed/object_loader_spec.rb",
70
81
  "spec/spec_helper.rb"
71
82
  ]
72
83
 
@@ -0,0 +1,105 @@
1
+ module Aws
2
+ module Authentication
3
+
4
+ include AWS
5
+
6
+ AMAZON_ACCESS_KEY_ID = ENV['AMAZON_ACCESS_KEY_ID']
7
+ AMAZON_SECRET_ACCESS_KEY = ENV['AMAZON_SECRET_ACCESS_KEY']
8
+ SIGNATURE_VERSION = '2'
9
+
10
+ def aws_access_key_id
11
+ AMAZON_ACCESS_KEY_ID
12
+ end
13
+
14
+ def aws_secret_access_key
15
+ AMAZON_SECRET_ACCESS_KEY
16
+ end
17
+
18
+ def new_digest
19
+ OpenSSL::Digest::Digest.new('sha256')
20
+ end
21
+
22
+ def sign(string)
23
+ Base64.encode64(OpenSSL::HMAC.digest(new_digest, aws_secret_access_key, string)).strip
24
+ end
25
+
26
+ # Escape the nonreserved AWS characters. Use this instead of URI.escape or CGI.escape
27
+ # See String#unpack for hex nibbles: http://ruby-doc.org/core/classes/String.html#M000760
28
+ def aws_escape(string)
29
+ string.to_s.gsub(/([^a-zA-Z0-9._~-]+)/n) { '%' + $1.unpack('H2' * $1.size).join('%').upcase }
30
+ end
31
+
32
+ def aws_escape_params(params, opts = {})
33
+ request = params.merge(opts)
34
+ request.inject({}) { |h,(k,v)| h[aws_escape(k)] = aws_escape(v);h }
35
+ end
36
+
37
+ def uri_escape_params(params, opts = {})
38
+ request = params.merge(opts)
39
+ request.inject({}) { |h,(k,v)| h[URI.escape(k.to_s)] = URI.escape(v.to_s);h }
40
+ end
41
+
42
+ # Create an AWS signature
43
+ # From: http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/
44
+ # String to sign:
45
+ # HTTPVerb + "\n" +
46
+ # ValueOfHostHeaderInLowercase + "\n" +
47
+ # HTTPRequestURI + "\n" +
48
+ # CanonicalizedQueryString
49
+ # Calculate an RFC 2104-compliant HMAC with the string you just created, your Secret Access Key as the key.
50
+ # We use SHA256 as the hash algorithm.
51
+ # Do not encode the signature here. The string will be encoded when it's included in the query string.
52
+ #def aws_signature(httpverb, host, requesturi, params = {})
53
+ # sorted_params = params.sort.inject({}) { |h,(k,v)| h[k] = v;h }
54
+ # query_string = aws_escape_params(sorted_params).collect { |k,v| k + '=' + v }.join('&')
55
+ # string_to_sign = "#{httpverb.to_s.upcase}\n#{host}\n#{requesturi}\n#{query_string}"
56
+ # puts "STRING TO SIGN is " + string_to_sign.inspect
57
+ # sign(string_to_sign)
58
+ #end
59
+ def generate_string_to_sign(httpverb, host, uri, params = {})
60
+ verb = httpverb.to_s.upcase
61
+ sorted_params = params.sort.inject({}) { |h,(k,v)| h[k] = v;h }
62
+ query_string = aws_escape_params(sorted_params).collect { |k,v| k + '=' + v }.join('&')
63
+ "#{verb}\n#{host}\n#{uri}\n#{query_string}"
64
+ end
65
+
66
+ def generate_query(action, params = {})
67
+ request_hash = generate_request(action, params)
68
+ uri = url_path || "/"
69
+ uri = uri + "/" unless uri == "/"
70
+ string_to_sign = generate_string_to_sign(:get, @host, uri, request_hash)
71
+ signature = aws_signature(string_to_sign)
72
+ generate_query_string(request_hash, 'Signature' => signature)
73
+ end
74
+
75
+ def aws_signature(string_to_sign)
76
+ sign(string_to_sign)
77
+ end
78
+
79
+ def generate_request(action, params = {})
80
+ request = {
81
+ 'Action' => action,
82
+ 'SignatureMethod' => 'HmacSHA256',
83
+ 'AWSAccessKeyId' => aws_access_key_id,
84
+ 'SignatureVersion' => SIGNATURE_VERSION
85
+ }
86
+ request.merge(default_params).merge(params)
87
+ end
88
+
89
+
90
+ def generate_query_string(params, opts = {})
91
+ query_hash = params.merge(opts)
92
+ query_string = URI.escape(query_hash.collect { |k,v| k.to_s + '=' + v.to_s }.join('&'))
93
+ query_string.gsub(/\+/, "%2B") #encode pluses correctly
94
+ end
95
+
96
+ def generate_query(action, params = {})
97
+ request_hash = generate_request(action, params)
98
+ uri = url_path || "/"
99
+ uri = uri + "/" unless uri == "/"
100
+ string_to_sign = generate_string_to_sign(:get, @host, uri, request_hash)
101
+ signature = aws_signature(string_to_sign)
102
+ generate_query_string(request_hash, 'Signature' => signature)
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,25 @@
1
+ require 'base64'
2
+ require 'openssl'
3
+ require 'time'
4
+ require 'typhoeus'
5
+ require 'crack'
6
+ require 'uri'
7
+ require 'cgi'
8
+
9
+ module AWS
10
+
11
+ include Typhoeus
12
+ include Crack
13
+
14
+ # AWS time xml format: YYYY-MM-DDThh:mm:ssZ> Zone is set to Z or UTC
15
+ def time_xml
16
+ Time.now.utc.xmlschema
17
+ end
18
+
19
+ def http_get_xml(host, path, request_params)
20
+ path = path == "/" ? path : path + "/"
21
+ req = path + "?" + request_params
22
+ res = Request.get(@host + req)
23
+ XML.parse res.body
24
+ end
25
+ end
@@ -0,0 +1,142 @@
1
+ module Aws
2
+ module Sqs
3
+
4
+ DEFAULT_HOST = 'queue.amazonaws.com'
5
+ API_VERSION = '2009-02-01'
6
+
7
+ class Queue
8
+
9
+ include Aws::Authentication
10
+ include Aws
11
+ include Crack
12
+
13
+ REQUEST_TTL = 600
14
+
15
+ attr_reader :host, :path, :expires
16
+
17
+ def initialize(queue_name = nil)
18
+ @host = DEFAULT_HOST
19
+ @queue_name = queue_name
20
+ @path = queue_name.nil? ? "/" : get_http_path if @path.nil?
21
+ end
22
+
23
+ # Get the queue path using Action = +ListQueues+ and additional param +QueneNamePrefix+.
24
+ # Example response +/12345678012/exampleQueue+
25
+ def get_http_path
26
+ action = 'ListQueues'
27
+ params = { "QueueNamePrefix" => @queue_name }.merge(default_params)
28
+ path = url_path || ""
29
+ xml_doc = http_get_xml(@host, path, generate_query(action, params))
30
+ url = (xml_doc["ListQueuesResponse"]["ListQueuesResult"]["QueueUrl"])
31
+ url = url[0] if Array === url
32
+ URI.parse(url).path
33
+ end
34
+
35
+ def url_path
36
+ @path || '/'
37
+ end
38
+
39
+ # List all the queues that start with the prefix.
40
+ def list_queues(prefix = "")
41
+ action = "ListQueues"
42
+ @path = "/"
43
+ available_queues = Array.new
44
+ xml_doc = http_get_xml(@host, path, generate_query(action, default_params))
45
+ if xml_doc["ListQueuesResponse"]["ListQueuesResult"]["QueueUrl"]
46
+ xml_doc["ListQueuesResponse"]["ListQueuesResult"]["QueueUrl"].each do |url|
47
+ available_queues << url.split("/").last
48
+ end
49
+ end
50
+ available_queues
51
+ end
52
+
53
+ def attributes
54
+ action = "GetQueueAttributes"
55
+ params = { "AttributeName" =>"All" }.merge(default_params)
56
+ http_get_xml(@host, @path, generate_query(action, params))
57
+ end
58
+
59
+ def create(queue_name)
60
+ action = "CreateQueue"
61
+ params = { "QueueName" => queue_name}
62
+ params.merge!(default_params)
63
+ @path = "/"
64
+ http_get_xml(@host, @path, generate_query(action, params))
65
+ end
66
+
67
+ def send(message, send_params = nil)
68
+ action = "SendMessage"
69
+ params = { "MessageBody" => message }.merge(default_params)
70
+ http_get_xml(@host, url_path, generate_query(action, params))
71
+ end
72
+
73
+ def receive(receive_params = {})
74
+ action = "ReceiveMessage"
75
+ params = {
76
+ "MaxNumberOfMessages" => receive_params[:number] || 1,
77
+ "AttributeName" => "All" }
78
+ params["VisibilityTimeout"] = receive_params[:timeout] if receive_params[:timeout]
79
+ params.merge!(default_params)
80
+ xml = http_get_xml(@host, url_path, generate_query(action, params))
81
+
82
+ if !xml["ReceiveMessageResponse"]["ReceiveMessageResult"].nil?
83
+ message = xml["ReceiveMessageResponse"]["ReceiveMessageResult"]["Message"]
84
+ @message_body = message["Body"]
85
+ @message_attribute = message["Attribute"]
86
+ @receipt_handle = message["ReceiptHandle"]
87
+ @message = message
88
+ else
89
+ nil
90
+ end
91
+ end
92
+
93
+ def receipt_handle
94
+ @receipt_handle
95
+ end
96
+
97
+ def message
98
+ @message
99
+ end
100
+
101
+ def message_body
102
+ @message_body
103
+ end
104
+
105
+ def message_attributes
106
+ @message_attribute
107
+ end
108
+
109
+ def delete(receipt_handle)
110
+ action = "DeleteMessage"
111
+ #unescaped_handle = URI.unescape(receipt_handle)
112
+ params = { "ReceiptHandle" => receipt_handle }.merge(default_params)
113
+ http_get_xml(@host, url_path, generate_query(action, params))
114
+ end
115
+
116
+ def delete_queue
117
+ action = "DeleteQueue"
118
+ params = default_params
119
+ http_get_xml(@host, url_path, generate_query(action, params))
120
+ end
121
+
122
+ # +time+ is expressed as a string.
123
+ def expires(time = nil)
124
+ if !time
125
+ (Time.now.utc + REQUEST_TTL).xmlschema
126
+ else
127
+ (Time.parse(time) + REQUEST_TTL).xmlschema
128
+ end
129
+ end
130
+
131
+ def default_params
132
+ request = {
133
+ 'Expires' => expires,
134
+ 'Version' => API_VERSION
135
+ }
136
+ end
137
+
138
+ def create_request(uri, query_string = nil)
139
+ end
140
+ end
141
+ end
142
+ end
@@ -5,64 +5,68 @@ module Lamed
5
5
 
6
6
  include Rack
7
7
  include Lamed::Helper
8
- extend Lamed::Helper
8
+ #extend Lamed::Helper
9
9
  include Lamed::Model
10
-
11
- attr_accessor :query, :path, :self_path, :env
12
-
13
- def set_self_path(str)
10
+
11
+ def self_path(str)
14
12
  @self_path = str
15
13
  end
16
-
17
- def parse_uri(request_path)
14
+
15
+ def req_params
16
+ env
17
+ end
18
+
19
+ def content_type(content_type)
20
+ req_params[:content_type] = content_type
21
+ end
22
+
23
+ def user_agent
24
+ req_params['HTTP_USER_AGENT']
25
+ end
26
+
27
+ # Find the uri's as and array of symbols from the request_path
28
+ def uri(request_path)
18
29
  begin
19
30
  uri = (request_path.split("/").collect {|r| r.downcase.intern unless r.empty?}).compact
20
31
  rescue NoMethodError
21
32
  uri = Array.new
22
33
  end
23
- return uri
34
+ @uri = uri
24
35
  end
25
-
26
- def parse_query_string(query_string)
36
+
37
+ # Build param symbols from the query string
38
+ def params(query_string)
27
39
  begin
28
- params = query_string.split('&').inject({}) { |h,(k,v)|
40
+ params_prime = query_string.split('&').inject({}) { |h,(k,v)|
29
41
  values = k.split('=')
30
42
  # Drop any query params that have blank values
31
43
  h[values[0].downcase.intern] = (CGI.unescape(values[1])).downcase if values.length == 2
32
44
  h
33
45
  }
34
46
  rescue NoMethodError => e
35
- params = Hash.new
47
+ params_prime = Hash.new
36
48
  end
37
- return params
49
+ params_prime
38
50
  end
39
-
40
- def call(env)
41
- @env = env
42
- env[:query] = self.parse_query_string(env['QUERY_STRING'])
43
- env[:path] = self.parse_uri(env['SCRIPT_NAME'])
44
- response(env)
45
- resp = @req_params
51
+
52
+ def call
53
+ #@env = env unless defined?(@env)
54
+ env[:query] = self.params(env['QUERY_STRING'])
55
+ env[:path] = self.uri(env['SCRIPT_NAME'])
56
+ response
57
+ resp = req_params
46
58
  status_code = resp[:status_code] || 200
47
59
  content_type = resp[:content_type] || "text/html"
48
60
  [status_code, {"Content-Type" => content_type}, [resp[:body]]]
49
61
  end
50
-
62
+
63
+ # This is just a reminder that I need to add something here
51
64
  def request(*args)
52
65
  end
53
66
 
54
- def response(req_params)
55
- @req_params = req_params
56
- @req_params[:body] = self.render
57
- return @req_params
58
- end
59
-
60
- def content_type(content_type)
61
- @req_params[:content_type] = content_type
62
- end
63
-
64
- def user_agent
65
- @env['HTTP_USER_AGENT']
67
+ def response
68
+ req_params[:body] = self.render
69
+ #return @req_params
66
70
  end
67
71
  end
68
72
  end
@@ -5,6 +5,9 @@ require 'memcached'
5
5
  require 'cgi'
6
6
  require 'lib/lamed/helper'
7
7
  require 'lib/lamed/object_loader'
8
+ require 'lib/lamed/aws/aws'
9
+ require 'lib/lamed/aws/authentication'
10
+ require 'lib/lamed/aws/sqs'
8
11
 
9
12
  module Lamed
10
13
 
@@ -69,6 +72,10 @@ module Lamed
69
72
  @logger
70
73
  end
71
74
 
75
+ def opts
76
+ @opts = SYS_OPTIONS
77
+ end
78
+
72
79
  def load_lib
73
80
  Dir[ROOT + '/lib/**/*.rb'].each {|f| load f}
74
81
  end
data/lib/lamed/main.rb CHANGED
@@ -16,6 +16,8 @@ module Rack
16
16
 
17
17
  def run_apps
18
18
  use Rack::Lint
19
+ use Rack::ShowExceptions
20
+ use Rack::CommonLogger
19
21
  ObjectLoader.mapped_class.each_pair do |path, klass|
20
22
  map path do
21
23
  run klass.new
data/lib/lamed/model.rb CHANGED
@@ -1,14 +1,38 @@
1
1
  require 'mysql'
2
- require 'lib/lamed/redis'
2
+ require 'dm-core'
3
+ require 'dm-types'
4
+ require 'dm-aggregates'
5
+ #require 'lib/lamed/redis'
6
+ require 'redis'
3
7
 
4
8
  module Lamed
5
9
 
6
10
  module Model
11
+
12
+ #LAME_ROOT = ::LAME_ROOT unless defined?(LAME_ROOT)
13
+
14
+ end
15
+
16
+ # Support for DataMapper
17
+ class DM
7
18
 
8
- #include Lamed
19
+ #include DataMapper::Resource
20
+ include DataMapper
9
21
 
10
- LAME_ROOT = ::LAME_ROOT unless defined?(LAME_ROOT)
11
-
22
+ # Setup the database connection using DataMapper
23
+ def initialize(params = {})
24
+ @host = params[:host] || 'localhost'
25
+ @port = (params[:port] || 3306).to_i
26
+ @user = params[:username] || 'root'
27
+ @password = params[:password] || 'pwd'
28
+ @database = params[:database] || 'ithingy'
29
+ @adapter = params[:adapter] || 'mysql'
30
+ self.connect
31
+ end
32
+
33
+ def connect(params = {})
34
+ DataMapper.setup(:default, "#{@adapter}://#{@user}:#{@password}@#{@host}:#{@port}/#{@database}")
35
+ end
12
36
  end
13
37
 
14
38
  class MySQL < Mysql
@@ -67,4 +91,31 @@ module Lamed
67
91
  return res
68
92
  end
69
93
  end
94
+ end
95
+
96
+ class Redis
97
+
98
+ # Adding namespace or prefix keys to redis SET and GET request much like memcache.
99
+
100
+ $SYS_OPTIONS = {} unless defined?($SYS_OPTIONS)
101
+
102
+ REDIS_OPTIONS = {
103
+ :host => $SYS_OPTIONS[:redis_host] || '127.0.0.1' ,
104
+ :port => ($SYS_OPTIONS[:redis_port] || 6379).to_i,
105
+ :db => ($SYS_OPTIONS[:redis_db] || 0).to_i,
106
+ :timeout => ($SYS_OPTIONS[:redis_timeout] || 5).to_i,
107
+ }
108
+
109
+ def initialize(host, opts={})
110
+ @host = host || REDIS_OPTIONS[:host]
111
+ @port = opts[:port] || REDIS_OPTIONS[:port]
112
+ @db = opts[:db] || REDIS_OPTIONS[:db]
113
+ @timeout = opts[:timeout] || REDIS_OPTIONS[:timeout]
114
+ $debug = opts[:debug]
115
+ connect_to_server
116
+ end
117
+
118
+ def load
119
+ end
120
+
70
121
  end
data/lib/lamed/redis.rb CHANGED
@@ -22,4 +22,7 @@ class Redis
22
22
  connect_to_server
23
23
  end
24
24
 
25
+ def load
26
+ end
27
+
25
28
  end
@@ -1,2 +1,11 @@
1
1
  development:
2
+ main_cache: ['127.0.0.1:11211']
3
+ redis_host: '127.0.0.1'
4
+ redis_port: 6389
5
+ http_procs: 1
6
+ workers: 1
7
+ port: 3000
8
+ run_as: reco
9
+ pid: /var/run/
10
+ logs: /var/log/nutsie_radio
2
11
  rotate: daily
@@ -1,7 +1,8 @@
1
1
  class HelloWorld < Lamed::Controller
2
2
 
3
3
  def say_hello
4
- @req_params[:content_type] = 'text/html'
4
+ content_type = 'text/html'
5
+ puts env
5
6
  hello = "Hello World. We just got LaMeD!"
6
7
  return hello
7
8
  end
@@ -1,7 +1,7 @@
1
1
  class Bar < Lamed::Controller
2
2
 
3
3
  def say_hello
4
- @req_params[:content_type] = 'text/html'
4
+ content_type = 'text/html'
5
5
  hello = "Hello. This is the #{self.to_s} controller"
6
6
  return hello
7
7
  end
@@ -1,7 +1,7 @@
1
1
  class Foo < Lamed::Controller
2
2
 
3
3
  def say_hello
4
- @req_params[:content_type] = 'text/html'
4
+ content_type = 'text/html'
5
5
  hello = "Hello. This is the #{self.to_s} controller"
6
6
  return hello
7
7
  end
@@ -1,2 +1,8 @@
1
- class BarModel < Lamed::MySQL
1
+ class BarModel
2
+
3
+ include DataMapper::Resource
4
+
5
+ property :id, Serial, :length => 10
6
+ property :title, String, :length => 64, :key => true
7
+
2
8
  end
@@ -0,0 +1,58 @@
1
+ LAME_ROOT = File.join(File.dirname(__FILE__), '..')
2
+ ROOT = File.join(LAME_ROOT, "/spec/examples")
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
4
+
5
+ ENV['AMAZON_ACCESS_KEY_ID'] = 'THISISTHEACCESSKEYYO'
6
+ ENV['AMAZON_SECRET_ACCESS_KEY'] = 'THISISTHESECRETACCESSKEYYEAHBOISHOOBIDOO'
7
+
8
+ require 'lib/lamed/aws/aws'
9
+ require 'lib/lamed/aws/authentication'
10
+
11
+ include Aws::Authentication
12
+
13
+ describe Aws::Authentication do
14
+
15
+ it "should get AWS access id, secret, and new digest from system" do
16
+ aws_access_key_id.should == 'THISISTHEACCESSKEYYO'
17
+ aws_secret_access_key.should == 'THISISTHESECRETACCESSKEYYEAHBOISHOOBIDOO'
18
+ new_digest.inspect.should =~ /\#<OpenSSL::Digest::Digest:/
19
+ end
20
+
21
+ it "should escape string in an AWS friendly way" do
22
+ string = 'Hello World. This:is:not-what-you-want'
23
+ aws_escape(string).should == 'Hello%20World.%20This%3Ais%3Anot-what-you-want'
24
+ end
25
+
26
+ it "should escape params in an AWS friendly way" do
27
+ hash = {
28
+ 'foo' => 'Hello World',
29
+ 'foo:bar' => 'Rock-around-the-world'
30
+ }
31
+ aws_escape_params(hash).should == {"foo"=>"Hello%20World", "foo%3Abar"=>"Rock-around-the-world"}
32
+ end
33
+
34
+ it "should URI escape params" do
35
+ hash = {
36
+ 'foo' => 'Hello World',
37
+ 'foo:bar' => 'Rock-around-the-world'
38
+ }
39
+ uri_escape_params(hash, :ho => 'test').should == {"foo"=>"Hello%20World", "foo:bar"=>"Rock-around-the-world", "ho"=> "test"}
40
+ end
41
+
42
+ it "should generate the string to sign" do
43
+ self.should_receive(:default_params).and_return("foo" => 'bar')
44
+ uri = '/123456789012/exampleQueue'
45
+ httpverb = "GET"
46
+ host = 'queue.amazonaws.com'
47
+ generate_string_to_sign(httpverb, host, uri, params = {}).should == ''
48
+ end
49
+
50
+ it "should generate the query using action ListQueues" do
51
+ self.should_receive(:default_params).and_return("foo" => 'bar')
52
+ self.should_receive(:url_path).and_return('/123456789012/exampleQueue')
53
+ action = "ListQueues"
54
+ params = { 'QueueNamePrefix' => 'exampleQueue' }
55
+ generate_query(action, params).should == ''
56
+ end
57
+
58
+ end
@@ -0,0 +1,13 @@
1
+ LAME_ROOT = File.join(File.dirname(__FILE__), '..')
2
+ ROOT = File.join(LAME_ROOT, "/spec/examples")
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
4
+
5
+ require 'time'
6
+ require 'lib/lamed/aws/aws'
7
+
8
+ include AWS
9
+ describe "Return time object in xmlschema format" do
10
+ it "should return a time string in xml schema format" do
11
+ time_xml.should == Time.now.utc.xmlschema
12
+ end
13
+ end
@@ -0,0 +1,95 @@
1
+ #LAME_ROOT = File.join(File.dirname(__FILE__), '..')
2
+ #ROOT = File.join(LAME_ROOT, "/spec/examples")
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
4
+
5
+
6
+ ENV['AMAZON_ACCESS_KEY_ID'] = 'THISISTHEACCESSKEYYO'
7
+ ENV['AMAZON_SECRET_ACCESS_KEY'] = 'THISISTHESECRETACCESSKEYYEAHBOISHOOBIDOO'
8
+
9
+ require 'lib/lamed/aws/aws'
10
+ require 'lib/lamed/aws/authentication'
11
+ require 'lib/lamed/aws/sqs'
12
+ require 'spec_helper.rb'
13
+
14
+ include Aws
15
+
16
+ describe Aws::Sqs::Queue do
17
+ end
18
+ =begin
19
+ #it "should initialize a queue" do
20
+ # sqs = Sqs::Queue.new('prod_scs_completed_imports')
21
+ #end
22
+
23
+ before(:each) do
24
+ @sqs = Sqs::Queue.new()
25
+ end
26
+
27
+ it "should generate a request hash" do
28
+ @sqs.generate_request('ListQueues').should == {
29
+ "Action" => "ListQueues",
30
+ "SignatureMethod" => "HmacSHA256",
31
+ "AWSAccessKeyId" => ENV['AMAZON_ACCESS_KEY_ID'],
32
+ "SignatureVersion" => "2",
33
+ "Expires" => @sqs.expires,
34
+ "Version" => "2009-02-01"
35
+ }
36
+ end
37
+
38
+ it "should generate the string that will be signed" do
39
+ params = {
40
+ "Action" => "ListQueues",
41
+ "SignatureMethod" => "HmacSHA256",
42
+ "AWSAccessKeyId" => ENV['AMAZON_ACCESS_KEY_ID'],
43
+ "SignatureVersion" => "2",
44
+ "Expires" => "2010-02-10T21:24:40Z",
45
+ "Version" => "2009-02-01"
46
+ }
47
+ @sqs.generate_string_to_sign(:get, 'queue.amazonaws.com', '/', params).should == "GET\nqueue.amazonaws.com\n/\nAWSAccessKeyId=" +
48
+ "THISISTHEACCESSKEYYO&Action=ListQueues&Expires=" +
49
+ "2010-02-10T21%3A24%3A40Z&SignatureMethod=" +
50
+ "HmacSHA256&SignatureVersion=2&Version=2009-02-01"
51
+ end
52
+
53
+ it "should generate a request signature" do
54
+ string_to_sign = "GET\nqueue.amazonaws.com\n/\nAWSAccessKeyId=" +
55
+ "1NK7GFJZMZPXRPE6S802&Action=ListQueues&Expires=" +
56
+ "2010-02-10T21%3A24%3A40Z&SignatureMethod=" +
57
+ "HmacSHA256&SignatureVersion=2&Version=2009-02-01"
58
+ @sqs.aws_signature(string_to_sign).should == 'UyAhOaBN7ye4GQ2lhgY3aYGUWy3Rb64S6Y6T/u/vb5o='
59
+ end
60
+
61
+ it "should generate a SQS query hash with queue list request" do
62
+ @list_queue_query_string = @sqs.generate_query("ListQueues", 'QueueNamePrefix' => 'prod')
63
+ @list_queue_query_string.should =~ /Action=ListQueues&SignatureMethod=HmacSHA256&AWSAccessKeyId=THISISTHEACCESSKEYYO&SignatureVersion=2&Expires=/
64
+ end
65
+
66
+ it "should create a new queue" do
67
+ @sqs.create("test_scs_completed_imports").inspect.should =~ /CreateQueueResponse/
68
+ end
69
+
70
+ it "should list a queue's attribute" do
71
+ @sqs.attributes.inspect.should =~ /GetQueueAttributesResponse/
72
+ end
73
+
74
+ it "should get a url path for a SQS queue" do
75
+ @sqs.path.should == '/002611861940/test_scs_completed_imports'
76
+ end
77
+
78
+ it "should send a message" do
79
+ msg = "This is a test"
80
+ @sqs.send(msg).inspect.should =~ /SendMessageResponse/
81
+ end
82
+
83
+ it "should receive the test message" do
84
+ @sqs.receive
85
+ message = sqs.message
86
+ @@receipt_handle = message["ReceiptHandle"]
87
+ message.inspect.should =~ /MessageId/
88
+ end
89
+
90
+ it "should delete the message from the queue" do
91
+ receipt_handle = @@receipt_handle
92
+ @sqs.delete(receipt_handle).inspect.should =~ /DeleteMessageResponse/
93
+ end
94
+ end
95
+ =end
@@ -0,0 +1,88 @@
1
+ LAME_ROOT = File.join(File.dirname(__FILE__), '..')
2
+ #ROOT = File.join(LAME_ROOT, "/spec/examples")
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
4
+
5
+ require 'rack'
6
+ require 'spec_helper'
7
+ require 'lib/lamed/model'
8
+ require 'lib/lamed/helper'
9
+ require 'lib/lamed/controller'
10
+
11
+ module Lamed
12
+
13
+ describe Controller do
14
+
15
+ it "Controller should exist" do
16
+ Controller.should == Lamed::Controller
17
+ end
18
+
19
+ it "Controller should have instance methods" do
20
+ Controller.instance_methods(false).sort.should == [:call, :content_type, :params, :req_params, :request, :response, :self_path, :uri, :user_agent]
21
+ end
22
+
23
+ it "Controller should have methods" do
24
+ Controller.methods(false).sort.should == []
25
+ end
26
+
27
+ let(:controller) { Controller.new }
28
+ let(:env) { { "GATEWAY_INTERFACE"=>"CGI/1.1", "PATH_INFO"=>"", "QUERY_STRING"=>"hello=test&foo=bar",
29
+ "REMOTE_ADDR"=>"127.0.0.1", "REMOTE_HOST"=>"radio.local", "REQUEST_METHOD"=>"GET",
30
+ "REQUEST_URI"=>"http://localhost:9292/hello_world?hello=test&foo=bar", "SCRIPT_NAME"=>"/hello_world",
31
+ "SERVER_NAME"=>"localhost", "SERVER_PORT"=>"9292", "SERVER_PROTOCOL"=>"HTTP/1.1",
32
+ "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.9.1/2009-12-07)", "HTTP_HOST"=>"localhost:9292",
33
+ "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7",
34
+ "HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "HTTP_ACCEPT_LANGUAGE"=>"en-us,en;q=0.5",
35
+ "HTTP_ACCEPT_ENCODING"=>"gzip,deflate", "HTTP_ACCEPT_CHARSET"=>"UTF-8,*", "HTTP_KEEP_ALIVE"=>"300",
36
+ "HTTP_CONNECTION"=>"keep-alive", "HTTP_CACHE_CONTROL"=>"max-age=0", "rack.version"=>[1, 0],
37
+ "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false, "rack.url_scheme"=>"http",
38
+ "HTTP_VERSION"=>"HTTP/1.1", "REQUEST_PATH"=>"/hello_world" } }
39
+
40
+ before(:each) do
41
+ controller.stub(:env).and_return(env)
42
+ end
43
+
44
+ it "request_params" do
45
+ controller.req_params.should == {"GATEWAY_INTERFACE"=>"CGI/1.1", "PATH_INFO"=>"", "QUERY_STRING"=>"hello=test&foo=bar",
46
+ "REMOTE_ADDR"=>"127.0.0.1", "REMOTE_HOST"=>"radio.local", "REQUEST_METHOD"=>"GET", "REQUEST_URI"=>"http://localhost:9292/hello_world?hello=test&foo=bar",
47
+ "SCRIPT_NAME"=>"/hello_world", "SERVER_NAME"=>"localhost", "SERVER_PORT"=>"9292", "SERVER_PROTOCOL"=>"HTTP/1.1",
48
+ "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.9.1/2009-12-07)", "HTTP_HOST"=>"localhost:9292",
49
+ "HTTP_USER_AGENT"=>"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7",
50
+ "HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "HTTP_ACCEPT_LANGUAGE"=>"en-us,en;q=0.5",
51
+ "HTTP_ACCEPT_ENCODING"=>"gzip,deflate", "HTTP_ACCEPT_CHARSET"=>"UTF-8,*", "HTTP_KEEP_ALIVE"=>"300", "HTTP_CONNECTION"=>"keep-alive",
52
+ "HTTP_CACHE_CONTROL"=>"max-age=0", "rack.version"=>[1, 0], "rack.multithread"=>true, "rack.multiprocess"=>false, "rack.run_once"=>false,
53
+ "rack.url_scheme"=>"http", "HTTP_VERSION"=>"HTTP/1.1", "REQUEST_PATH"=>"/hello_world"}
54
+ end
55
+
56
+ it "should set content type" do
57
+ controller.content_type('text/html').should == 'text/html'
58
+ end
59
+
60
+ it "should get user_agent" do
61
+ controller.user_agent.should == 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7'
62
+ end
63
+
64
+ it "get uri" do
65
+ controller.uri(env["REQUEST_PATH"]).should == [:hello_world]
66
+ end
67
+
68
+ it "get params" do
69
+ controller.params(env["QUERY_STRING"]).should == {:hello=>"test", :foo=>"bar"}
70
+ end
71
+
72
+ it "set path" do
73
+ controller.self_path('/usr/pub').should == '/usr/pub'
74
+ end
75
+
76
+ before(:each) do
77
+ controller.stub(:render).and_return('Hello World')
78
+ end
79
+
80
+ it "should return a response" do
81
+ controller.response.should == 'Hello World'
82
+ end
83
+
84
+ it "Controller.call" do
85
+ controller.call.should == [200, {"Content-Type"=>"text/html"}, ["Hello World"]]
86
+ end
87
+ end
88
+ end
@@ -24,7 +24,7 @@ module Lamed
24
24
  string = "foo_bar"
25
25
  cameled_string = camelize_string string
26
26
  cameled_string.should == "FooBar"
27
- end
27
+ end
28
28
 
29
29
  it "should uncamelize a cameled string into an uncameled _ seperated string" do
30
30
  string = "FooBar"
@@ -0,0 +1,42 @@
1
+ LAME_ROOT = File.join(File.dirname(__FILE__), '..')
2
+ ROOT = File.join(LAME_ROOT, "/spec/examples")
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
4
+
5
+ require 'rack'
6
+ require 'lib/lamed/initializer'
7
+ require 'spec/examples/ext/models/bar_model'
8
+
9
+
10
+ describe "Initialize all Lamed Objects" do
11
+ it "should initialize the logger to STDERR" do
12
+ Lamed.logger.level.should == 0
13
+ end
14
+
15
+ it "should initialize options to opts" do
16
+ Lamed.opts.should == {:main_cache=>["127.0.0.1:11211"], :redis_host=>"127.0.0.1", :redis_port=>6389, :http_procs=>1,
17
+ :workers=>1, :port=>3000, :run_as=>"reco", :pid=>"/var/run/", :logs=>"/var/log/nutsie_radio",
18
+ :rotate=>"daily"}
19
+ end
20
+
21
+ it "should initialize the Controller, Lib, and Model objects" do
22
+ Lamed::Model.constants.should == [:BarModel, :FooModel]
23
+ Lamed::Controller.constants.sort.should == [:HelloWorld, :Lamest, :BarModel, :FooModel, :VERSION, :Cascade, :Chunked,
24
+ :ConditionalGet, :ContentLength, :ContentType, :File, :Deflater, :Directory,
25
+ :ForwardRequest, :Handler, :Head, :Lint, :Lock, :MethodOverride, :Mime,
26
+ :Recursive, :Reloader, :ShowStatus, :Static, :URLMap, :MockRequest,
27
+ :MockResponse, :Response, :Auth, :Session, :Adapter, :Builder, :CommonLogger,
28
+ :Utils, :Request, :ShowExceptions, :Template, :ContextMiss, :Context].sort
29
+ Object.constants.include?(:FooLib).should == true
30
+ end
31
+ end
32
+
33
+ describe BarModel do
34
+ it "should load BarModel" do
35
+ BarModel.new.inspect.should =~ /BarModel @id=nil @title=nil/
36
+ BarModel.instance_variables.should == [:@valid, :@base_model, :@storage_names, :@default_order, :@descendants, :@relationships, :@properties,
37
+ :@field_naming_conventions, :@paranoid_properties, :@resource_methods]
38
+ end
39
+
40
+ it "return title request" do
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ LAME_ROOT = File.join(File.dirname(__FILE__), '..')
2
+ ROOT = File.join(LAME_ROOT, "/spec/examples")
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
4
+
5
+ require 'spec_helper'
6
+ require 'lib/lamed/model'
7
+
8
+ module Lamed
9
+ describe Model do
10
+
11
+ it "Model should exist" do
12
+ Model.should == Lamed::Model
13
+ end
14
+
15
+ it "should have instance methods" do
16
+ Model.instance_methods(false).should == []
17
+ end
18
+
19
+ it "should have methods" do
20
+ Model.methods(false).should == []
21
+ end
22
+ end
23
+
24
+ describe DM do
25
+
26
+ let(:dm) { DM.new(:host => 'localhost') }
27
+
28
+ it "should intialize DM" do
29
+ #dm = DM.new(:host => 'localhost')
30
+ dm.inspect.should =~ /Lamed/
31
+ end
32
+
33
+ it "should connect to the database with defaults" do
34
+ dm.connect.inspect.should =~ /DataMapper::Adapters::MysqlAdapter/
35
+ end
36
+ end
37
+
38
+ describe MySQL do
39
+
40
+ it "should initialize DM"
41
+ end
42
+ end
@@ -93,7 +93,7 @@ module Lamed
93
93
 
94
94
  it "should load up controllers" do
95
95
  ObjectLoader.load_controller_object
96
- Lamed.constants.should == [:Helper, :Model, :MySQL, :Controller, :ObjectLoader]
96
+ Lamed.constants.should == [:Helper, :Model, :DM, :MySQL, :Controller, :ObjectLoader]
97
97
  Lamed::Controller.constants.sort.should == [:Adapter, :Auth, :Builder, :Cascade, :Chunked, :CommonLogger,
98
98
  :ConditionalGet, :ContentLength, :ContentType, :Context, :ContextMiss,
99
99
  :Deflater, :Directory, :File, :ForwardRequest, :Handler, :Head,
@@ -106,10 +106,8 @@ module Lamed
106
106
 
107
107
  it "should load up models" do
108
108
  ObjectLoader.load_model_object
109
- Lamed.constants.should == [:Helper, :Model, :MySQL, :Controller, :ObjectLoader]
109
+ Lamed.constants.should == [:Helper, :Model, :DM, :MySQL, :Controller, :ObjectLoader]
110
110
  Lamed::Model.constants.should == [:BarModel, :FooModel]
111
- end
112
-
113
- end
114
-
111
+ end
112
+ end
115
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lamed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Chang
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-19 00:00:00 -08:00
12
+ date: 2010-04-15 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,9 @@ files:
50
50
  - VERSION
51
51
  - lamed.gemspec
52
52
  - lib/lamed.rb
53
+ - lib/lamed/aws/authentication.rb
54
+ - lib/lamed/aws/aws.rb
55
+ - lib/lamed/aws/sqs.rb
53
56
  - lib/lamed/controller.rb
54
57
  - lib/lamed/helper.rb
55
58
  - lib/lamed/initializer.rb
@@ -69,10 +72,14 @@ files:
69
72
  - spec/examples/ext/views/lamest/bar.mustache
70
73
  - spec/examples/ext/views/lamest/foo.mustache
71
74
  - spec/examples/lib/foo_lib.rb
72
- - spec/helpers_spec.rb
73
- - spec/initializer_spec.rb
74
- - spec/lame_spec.rb
75
- - spec/object_loader_spec.rb
75
+ - spec/lamed/aws/authentication_spec.rb
76
+ - spec/lamed/aws/spec.rb
77
+ - spec/lamed/aws/sqs_spec.rb
78
+ - spec/lamed/controller_spec.rb
79
+ - spec/lamed/helper_spec.rb
80
+ - spec/lamed/initializer_spec.rb
81
+ - spec/lamed/model_spec.rb
82
+ - spec/lamed/object_loader_spec.rb
76
83
  - spec/spec.opts
77
84
  - spec/spec_helper.rb
78
85
  has_rdoc: true
@@ -110,8 +117,12 @@ test_files:
110
117
  - spec/examples/ext/models/bar_model.rb
111
118
  - spec/examples/ext/models/foo_model.rb
112
119
  - spec/examples/lib/foo_lib.rb
113
- - spec/helpers_spec.rb
114
- - spec/initializer_spec.rb
115
- - spec/lame_spec.rb
116
- - spec/object_loader_spec.rb
120
+ - spec/lamed/aws/authentication_spec.rb
121
+ - spec/lamed/aws/spec.rb
122
+ - spec/lamed/aws/sqs_spec.rb
123
+ - spec/lamed/controller_spec.rb
124
+ - spec/lamed/helper_spec.rb
125
+ - spec/lamed/initializer_spec.rb
126
+ - spec/lamed/model_spec.rb
127
+ - spec/lamed/object_loader_spec.rb
117
128
  - spec/spec_helper.rb
@@ -1,26 +0,0 @@
1
- LAME_ROOT = File.join(File.dirname(__FILE__), '..')
2
- ROOT = File.join(LAME_ROOT, "/spec/examples")
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
4
-
5
- require 'rack'
6
- require 'lib/lamed/initializer'
7
-
8
-
9
- describe "Initialize all Lamed Objects" do
10
- it "should initialize the logger to STDERR" do
11
- Lamed.logger.level.should == 0
12
- end
13
-
14
- it "should initialize the Controller, Lib, and Model objects" do
15
- Lamed::Model.constants.should == [:BarModel, :FooModel]
16
- Lamed::Controller.constants.sort.should == [:HelloWorld, :Lamest, :BarModel, :FooModel, :VERSION, :Cascade, :Chunked,
17
- :ConditionalGet, :ContentLength, :ContentType, :File, :Deflater, :Directory,
18
- :ForwardRequest, :Handler, :Head, :Lint, :Lock, :MethodOverride, :Mime,
19
- :Recursive, :Reloader, :ShowStatus, :Static, :URLMap, :MockRequest,
20
- :MockResponse, :Response, :Auth, :Session, :Adapter, :Builder, :CommonLogger,
21
- :Utils, :Request, :ShowExceptions, :Template, :ContextMiss, :Context].sort
22
- Object.constants.include?(:FooLib).should == true
23
- end
24
-
25
- end
26
-
data/spec/lame_spec.rb DELETED
@@ -1,7 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Lamed" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
6
- end
7
- end