best3 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +13 -0
  4. data/Rakefile +2 -0
  5. data/best3.gemspec +21 -0
  6. data/lib/best3.rb +77 -0
  7. metadata +71 -0
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ gem 'typhoeus'
2
+ gem 'nokogiri'
@@ -0,0 +1,13 @@
1
+ GEM
2
+ specs:
3
+ nokogiri (1.4.3.1)
4
+ rack (1.2.1)
5
+ typhoeus (0.1.31)
6
+ rack
7
+
8
+ PLATFORMS
9
+ ruby
10
+
11
+ DEPENDENCIES
12
+ nokogiri
13
+ typhoeus
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ #-*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "best3"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "best3"
7
+ s.version = Best3::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ryan Allen"]
10
+ s.email = ["ryan@ryanface.com"]
11
+ s.homepage = "http://rubygems.org/gems/best3"
12
+ s.summary = %q{Minimal library for interacting with the Amazon Web Service API.}
13
+ s.description = %q{Are you depressed? Has high interest rates got you down? My name is Meatwad and today I'm here to offer you a once in a lifetime opportunity. Sell your organs, live, over the internet. Get money back on your baby!}
14
+
15
+ s.rubyforge_project = "best3"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ raise 'requires ruby 1.9.2' unless RUBY_VERSION == '1.9.2'
4
+ %w(rubygems bundler/setup typhoeus nokogiri strscan ostruct digest/sha1 time).each { |lib| require(lib) }
5
+
6
+ class Best3
7
+ VERSION = '0.0.1'
8
+
9
+ def initialize(*args)
10
+ @key, @secret = args
11
+ self
12
+ end
13
+
14
+ def s3()
15
+ Wrapper.new('http://s3.amazonaws.com', @key, @secret)
16
+ end
17
+
18
+ def cloudfront()
19
+ # cloudfront MUST use https
20
+ Wrapper.new('https://cloudfront.amazonaws.com', @key, @secret)
21
+ end
22
+
23
+ class Wrapper
24
+ def initialize(*args)
25
+ @host, @key, @secret = args
26
+ self
27
+ end
28
+
29
+ def call(request_method, uri, headers = {}, body = nil)
30
+ _(request_method, uri, headers.clone, body)
31
+ end
32
+
33
+ private
34
+
35
+ def _(request_method, uri, headers, body = nil)
36
+ response = Typhoeus::Request.send(request_method.downcase, "#{@host}#{uri}", :headers => make_headers(request_method, uri, headers, body), :body => body)
37
+ OpenStruct.new({:code => response.code, :headers => response.headers_hash, :body => Nokogiri::XML(response.body), :response => response})
38
+ end
39
+
40
+ def make_headers(request_method, uri, headers, body = nil)
41
+ headers['Date'] = Time.now.rfc822
42
+ headers['Authorization'] = make_auth(request_method, uri, headers, body)
43
+ headers
44
+ end
45
+
46
+ def make_auth(request_method, uri, headers, body = nil)
47
+ if @host == 'https://cloudfront.amazonaws.com'
48
+ # cloudfront only requires HMAC of the date
49
+ str = headers['Date']
50
+ else
51
+ str = []
52
+ str << request_method
53
+ str << ''
54
+ str << '' if not headers['Content-Type'] # get requests require an empty line instead of the content type but on a put if you omit it it'll set application/x-download and expect that to be signed
55
+ headers.keys.sort { |a, b| a.downcase <=> b.downcase }.each do |key|
56
+ if key.match(/^x-amz/i) # convert special amz headers to expected format
57
+ str << "#{key.downcase}:#{headers[key]}"
58
+ else
59
+ str << headers[key] # other headers just send the value
60
+ end
61
+ end
62
+ if uri.include?('&')
63
+ str << "#{StringScanner.new(uri).scan_until(/&/)[0..-2]}"
64
+ else
65
+ str << uri
66
+ end
67
+ str = str.join("\n").chomp
68
+ end
69
+ # auth key thingo stolen from aws::s3 library, lol.
70
+ "AWS #{@key}:#{[OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), @secret, str)].pack('m').strip}"
71
+ end
72
+ end
73
+ end
74
+
75
+ def Best3(*args) # i miss _why.
76
+ Best3.new(*args)
77
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: best3
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Ryan Allen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-07-18 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Are you depressed? Has high interest rates got you down? My name is Meatwad and today I'm here to offer you a once in a lifetime opportunity. Sell your organs, live, over the internet. Get money back on your baby!
22
+ email:
23
+ - ryan@ryanface.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - Gemfile.lock
34
+ - Rakefile
35
+ - best3.gemspec
36
+ - lib/best3.rb
37
+ has_rdoc: true
38
+ homepage: http://rubygems.org/gems/best3
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 2237202378153498057
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project: best3
66
+ rubygems_version: 1.3.7
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Minimal library for interacting with the Amazon Web Service API.
70
+ test_files: []
71
+