Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial.

  • Loading branch information...
commit 92918f576e6ce71ecbc19b2580d87aa500f492d4 0 parents
@cmeiklejohn authored
17 .gitignore
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
1  .rbenv-version
@@ -0,0 +1 @@
+1.9.3-p125
2  .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
3  Gemfile
@@ -0,0 +1,3 @@
+source :rubygems
+
+gemspec
6 Guardfile
@@ -0,0 +1,6 @@
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
+ watch('spec/spec_helper.rb') { "spec" }
+end
+
20 Rakefile
@@ -0,0 +1,20 @@
+#!/usr/bin/env rake
+
+require 'rubygems'
+require 'bundler'
+require 'bundler/gem_tasks'
+require 'rake'
+require 'rdoc/task'
+require 'rake/clean'
+require 'rubygems/package_task'
+require 'rspec/core/rake_task'
+
+include Rake::DSL
+
+Bundler::GemHelper.install_tasks
+
+RSpec::Core::RakeTask.new do |t|
+ t.pattern = 'spec/**/*_spec.rb'
+end
+
+task :default => [:spec]
29 hellion.gemspec
@@ -0,0 +1,29 @@
+# encoding: UTF-8
+
+$:.push File.expand_path("../lib", __FILE__)
+
+require "hellion/version"
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Christopher Meiklejohn"]
+ gem.email = ["christopher.meiklejohn@gmail.com"]
+ gem.description = %q{Amazon receipt processing.}
+ gem.summary = %q{Amazon receipt processing.}
+ gem.homepage = "http://github.com/cmeiklejohn/hellion"
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+
+ gem.name = "hellion"
+ gem.require_paths = ["lib"]
+ gem.version = Hellion::VERSION
+
+ gem.add_dependency('mail')
+
+ gem.add_development_dependency('rspec')
+ gem.add_development_dependency('rake','~> 0.9.2')
+
+ gem.add_development_dependency('guard')
+ gem.add_development_dependency('guard-rspec')
+end
13 lib/hellion.rb
@@ -0,0 +1,13 @@
+require 'hellion/version'
+require 'hellion/message'
+require 'hellion/receipt'
+
+module Hellion
+ class InvalidReceiptError < ArgumentError; end
+
+ class << self
+ def parse(receipt)
+ Message.new(receipt).to_receipt
+ end
+ end
+end
29 lib/hellion/message.rb
@@ -0,0 +1,29 @@
+require 'mail'
+
+module Hellion
+ class Message
+ attr_reader :raw, :message
+
+ def initialize(raw)
+ @raw = raw
+
+ initialize_message
+ end
+
+ def to_receipt
+ Receipt.new
+ end
+
+ private
+
+ def initialize_message
+ @message = Mail.read_from_string(raw)
+
+ raise_if_not_multipart
+ end
+
+ def raise_if_not_multipart
+ raise InvalidReceiptError unless @message.multipart?
+ end
+ end
+end
5 lib/hellion/receipt.rb
@@ -0,0 +1,5 @@
+module Hellion
+ class Receipt
+ attr_reader :items
+ end
+end
3  lib/hellion/version.rb
@@ -0,0 +1,3 @@
+module Hellion
+ VERSION = "0.0.1"
+end
21 spec/lib/hellion/message_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+module Hellion
+ describe Message do
+ subject { Message.new(receipt) }
+
+ context 'given a valid receipt' do
+ include_context 'a valid receipt'
+
+ it 'returns a new message object' do
+ subject.should be_an_instance_of(Message)
+ end
+
+ context 'once initialized' do
+ it 'contains a mail message object' do
+ subject.message.should be_an_instance_of(Mail::Message)
+ end
+ end
+ end
+ end
+end
6 spec/lib/hellion/receipt_spec.rb
@@ -0,0 +1,6 @@
+require 'spec_helper'
+
+module Hellion
+ describe Receipt do
+ end
+end
31 spec/lib/hellion_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+module Hellion
+ describe self do
+ context 'when parsing' do
+ subject { Hellion.parse(receipt) }
+
+ context 'an invalid receipt' do
+ include_context 'an invalid receipt'
+
+ it 'raises' do
+ lambda { subject }.should raise_error(InvalidReceiptError)
+ end
+ end
+
+ context 'a valid receipt' do
+ include_context 'a valid receipt'
+
+ it 'returns a receipt' do
+ subject.should be_an_instance_of(Receipt)
+ end
+
+ context 'the parsed receipt' do
+ before { subject }
+
+ its(:items) { should == items }
+ end
+ end
+ end
+ end
+end
22 spec/spec_helper.rb
@@ -0,0 +1,22 @@
+# encoding: UTF-8
+
+PROJECT_ROOT = File.expand_path("../..", __FILE__)
+$LOAD_PATH << File.join(PROJECT_ROOT, "lib")
+
+Bundler.require
+
+Dir[File.join(PROJECT_ROOT,"spec/support/**/*.rb")].each {|f| require f}
+
+require 'hellion'
+
+shared_context 'a valid receipt' do
+ let(:receipt) { File.read(File.join(PROJECT_ROOT, 'spec/support/receipts/email')) }
+
+ let(:items) do
+ [ { :title => 'The Art of Readable Code' } ]
+ end
+end
+
+shared_context 'an invalid receipt' do
+ let(:receipt) { "invalid." }
+end
Please sign in to comment.
Something went wrong with that request. Please try again.