diff --git a/.coveralls.yml b/.coveralls.yml
new file mode 100644
index 0000000..63dc78a
--- /dev/null
+++ b/.coveralls.yml
@@ -0,0 +1,2 @@
+service_name: travis-ci
+repo_token: q5fy5cVjHmq3yQ9iow8Nirl2aTc1fwEqE
diff --git a/.gitignore b/.gitignore
index d7cbe47..6922a96 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,23 @@
-Fallstudie.iml
-bcMaster/.idea
-bcMaster/target/
-bcMaster/*.iws
-bcMaster/*.iml
-bcMaster/*.ipr
+*.gem
+*.log
+*.rbc
+.bundle
+.config
+coverage
+InstalledFiles
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
+
+# YARD artifacts
+.yardoc
+_yardoc
+doc/
+
+#Config file for the database
+#config/database.yml
+
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..d375489
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,18 @@
+language: ruby
+
+rvm:
+ - 2.0.0
+
+branches:
+ only:
+ - master
+ - stable
+ - travis
+
+deploy:
+ provider: heroku
+ app:
+ master: bcmaster-dev
+ stable: bcmaster
+ api_key: b3f1822f-cc5b-459f-a7d6-d13ded0db51d
+
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..5091c36
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,58 @@
+source 'https://rubygems.org'
+#ruby '2.0.0'
+
+# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
+gem 'rails', '4.0.1'
+
+# Coveralls.io
+gem 'coveralls', require: false
+
+# Use postgresql as the database for Active Record
+gem 'pg'
+
+# Use SCSS for stylesheets
+gem 'sass-rails', '~> 4.0.0'
+
+# Use Uglifier as compressor for JavaScript assets
+gem 'uglifier', '>= 1.3.0'
+
+# Twitter Bootstrap sass
+gem 'bootstrap-sass'
+group :development do
+ gem 'rails_layout'
+end
+
+# Use CoffeeScript for .js.coffee assets and views
+gem 'coffee-rails', '~> 4.0.0'
+
+# See https://github.com/sstephenson/execjs#readme for more supported runtimes
+# gem 'therubyracer', platforms: :ruby
+
+# Use jquery as the JavaScript library
+gem 'jquery-rails'
+
+# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
+gem 'turbolinks'
+
+# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
+gem 'jbuilder', '~> 1.2'
+
+group :doc do
+ # bundle exec rake doc:rails generates the API under doc/api.
+ gem 'sdoc', require: false
+end
+
+# Use ActiveModel has_secure_password
+gem 'bcrypt-ruby', '~> 3.1.2'
+
+# Use unicorn as the app server
+# gem 'unicorn'
+
+# Use Capistrano for deployment
+# gem 'capistrano', group: :development
+
+# Use debugger
+# gem 'debugger', group: [:development, :test]
+
+# 12factor (http://12factor.net/)
+gem 'rails_12factor'
\ No newline at end of file
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..644eee4
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,150 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (4.0.1)
+ actionpack (= 4.0.1)
+ mail (~> 2.5.4)
+ actionpack (4.0.1)
+ activesupport (= 4.0.1)
+ builder (~> 3.1.0)
+ erubis (~> 2.7.0)
+ rack (~> 1.5.2)
+ rack-test (~> 0.6.2)
+ activemodel (4.0.1)
+ activesupport (= 4.0.1)
+ builder (~> 3.1.0)
+ activerecord (4.0.1)
+ activemodel (= 4.0.1)
+ activerecord-deprecated_finders (~> 1.0.2)
+ activesupport (= 4.0.1)
+ arel (~> 4.0.0)
+ activerecord-deprecated_finders (1.0.3)
+ activesupport (4.0.1)
+ i18n (~> 0.6, >= 0.6.4)
+ minitest (~> 4.2)
+ multi_json (~> 1.3)
+ thread_safe (~> 0.1)
+ tzinfo (~> 0.3.37)
+ arel (4.0.1)
+ atomic (1.1.14)
+ bcrypt-ruby (3.1.2)
+ bootstrap-sass (3.0.3.0)
+ sass (~> 3.2)
+ builder (3.1.4)
+ coffee-rails (4.0.1)
+ coffee-script (>= 2.2.0)
+ railties (>= 4.0.0, < 5.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.6.3)
+ coveralls (0.7.0)
+ multi_json (~> 1.3)
+ rest-client
+ simplecov (>= 0.7)
+ term-ansicolor
+ thor
+ docile (1.1.1)
+ erubis (2.7.0)
+ execjs (2.0.2)
+ hike (1.2.3)
+ i18n (0.6.9)
+ jbuilder (1.5.3)
+ activesupport (>= 3.0.0)
+ multi_json (>= 1.2.0)
+ jquery-rails (3.0.4)
+ railties (>= 3.0, < 5.0)
+ thor (>= 0.14, < 2.0)
+ json (1.8.1)
+ mail (2.5.4)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.25.1)
+ minitest (4.7.5)
+ multi_json (1.8.2)
+ pg (0.17.0)
+ polyglot (0.3.3)
+ rack (1.5.2)
+ rack-test (0.6.2)
+ rack (>= 1.0)
+ rails (4.0.1)
+ actionmailer (= 4.0.1)
+ actionpack (= 4.0.1)
+ activerecord (= 4.0.1)
+ activesupport (= 4.0.1)
+ bundler (>= 1.3.0, < 2.0)
+ railties (= 4.0.1)
+ sprockets-rails (~> 2.0.0)
+ rails_12factor (0.0.2)
+ rails_serve_static_assets
+ rails_stdout_logging
+ rails_layout (1.0.1)
+ rails_serve_static_assets (0.0.1)
+ rails_stdout_logging (0.0.3)
+ railties (4.0.1)
+ actionpack (= 4.0.1)
+ activesupport (= 4.0.1)
+ rake (>= 0.8.7)
+ thor (>= 0.18.1, < 2.0)
+ rake (10.1.0)
+ rdoc (3.12.2)
+ json (~> 1.4)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ sass (3.2.12)
+ sass-rails (4.0.1)
+ railties (>= 4.0.0, < 5.0)
+ sass (>= 3.1.10)
+ sprockets-rails (~> 2.0.0)
+ sdoc (0.3.20)
+ json (>= 1.1.3)
+ rdoc (~> 3.10)
+ simplecov (0.8.2)
+ docile (~> 1.1.0)
+ multi_json
+ simplecov-html (~> 0.8.0)
+ simplecov-html (0.8.0)
+ sprockets (2.10.1)
+ hike (~> 1.2)
+ multi_json (~> 1.0)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sprockets-rails (2.0.1)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ sprockets (~> 2.8)
+ term-ansicolor (1.2.2)
+ tins (~> 0.8)
+ thor (0.18.1)
+ thread_safe (0.1.3)
+ atomic
+ tilt (1.4.1)
+ tins (0.13.1)
+ treetop (1.4.15)
+ polyglot
+ polyglot (>= 0.3.1)
+ turbolinks (2.0.0)
+ coffee-rails
+ tzinfo (0.3.38)
+ uglifier (2.3.3)
+ execjs (>= 0.3.0)
+ json (>= 1.8.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bcrypt-ruby (~> 3.1.2)
+ bootstrap-sass
+ coffee-rails (~> 4.0.0)
+ coveralls
+ jbuilder (~> 1.2)
+ jquery-rails
+ pg
+ rails (= 4.0.1)
+ rails_12factor
+ rails_layout
+ sass-rails (~> 4.0.0)
+ sdoc
+ turbolinks
+ uglifier (>= 1.3.0)
diff --git a/README.md b/README.md
index 7dd76d0..ca9443d 100644
--- a/README.md
+++ b/README.md
@@ -1,17 +1,19 @@
bcMaster
========
+
+
+
Im Rahmen der Fallstudie im Fach «Methoden der Programmierung» des berufsbegleitenden
Bachelor-Studienganges Informatik an der ZHAW Zürich soll ein Bitcoin Trading Client
(bcMaster) programmiert werden.
-
Source Control
--------------
-Zur Source-Verwaltung verwenden wir git. Das Repository lassen wir von github hosten.
-Dies aus folgenden Gründen:
+Zur Source-Verwaltung verwenden wir git. Das Repository lassen wir von github hosten
+(vgl. Links am Ende). Dies aus folgenden Gründen:
* Das Projekt ist eine Übung und darf darum durchaus öffentlich zugängig sein.
* Es muss kein eigener Server aufgesetzt werden, was Zeit und Kosten spart.
@@ -21,8 +23,8 @@ Dies aus folgenden Gründen:
Build Control
-------------
-Für korrekte Builds werden wir eventuell [travis](https://travis-ci.org/) verwenden,
-da mit diesem Tool alle wichtigen Funktionen abgedeckt werden.
+Für korrekte Builds verwenden wir [travis](https://travis-ci.org/kressi/bcMaster), da
+mit diesem Tool alle wichtigen Funktionen abgedeckt werden.
Dieser Service ist gratis und lässt sich sehr gut zusammen mit github benutzen. Github
hat sogar eine travis-Integration.
@@ -31,9 +33,8 @@ hat sogar eine travis-Integration.
Projekt kompilieren
-------------------
-Die Art des Kompilierens ist noch nicht festgelegt worden (wahrscheinlich auch mit travis).
-Wir stellen so sicher, dass jedes Mitglied der Gruppe das Projekt korrekt verwenden kann
-(unter Berücksichtigung der Abhängigkeiten).
+Das Projekt kompilieren wir auch mit travis. Wir stellen so sicher, dass jedes Mitglied
+der Gruppe das Projekt korrekt verwenden kann (unter Berücksichtigung der Abhängigkeiten).
@@ -43,3 +44,15 @@ Tests
Tests können ebenso mit travis laufen gelassen werden.
+
+Links
+------
+
+* Project: http://www.hostedredmine.com/projects/bcmaster
+* Travis: https://travis-ci.org/kressi/bcMaster
+* Travis no JS: http://travis-lite.com/kressi/bcMaster
+* Prod Source: https://github.com/PinkSheep/bcMaster
+* Dev Source: https://github.com/kressi/bcMaster
+* Prod App: http://bcmaster.herokuapp.com
+* Dev App: http://bcmaster-dev.herokuapp.com
+
diff --git a/README.rdoc b/README.rdoc
new file mode 100644
index 0000000..dd4e97e
--- /dev/null
+++ b/README.rdoc
@@ -0,0 +1,28 @@
+== README
+
+This README would normally document whatever steps are necessary to get the
+application up and running.
+
+Things you may want to cover:
+
+* Ruby version
+
+* System dependencies
+
+* Configuration
+
+* Database creation
+
+* Database initialization
+
+* How to run the test suite
+
+* Services (job queues, cache servers, search engines, etc.)
+
+* Deployment instructions
+
+* ...
+
+
+Please feel free to use a different markup language if you do not plan to run
+rake doc:app.
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..c622688
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,6 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+
+BcMaster::Application.load_tasks
diff --git a/app/assets/javascripts/about.js.coffee b/app/assets/javascripts/about.js.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/about.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
new file mode 100644
index 0000000..cd5c291
--- /dev/null
+++ b/app/assets/javascripts/application.js
@@ -0,0 +1,17 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
+// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// compiled file.
+//
+// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
+// about supported directives.
+//
+//= require jquery
+//= require jquery_ujs
+//= require turbolinks
+//= require bootstrap
+//= require_tree .
diff --git a/app/assets/javascripts/main.js.coffee b/app/assets/javascripts/main.js.coffee
new file mode 100644
index 0000000..7615679
--- /dev/null
+++ b/app/assets/javascripts/main.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
diff --git a/app/assets/javascripts/trade.js.coffee b/app/assets/javascripts/trade.js.coffee
new file mode 100644
index 0000000..24f83d1
--- /dev/null
+++ b/app/assets/javascripts/trade.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
diff --git a/app/assets/main/bitcoin.png b/app/assets/main/bitcoin.png
new file mode 100644
index 0000000..089d2ef
Binary files /dev/null and b/app/assets/main/bitcoin.png differ
diff --git a/app/assets/main/exchange.png b/app/assets/main/exchange.png
new file mode 100644
index 0000000..fee4b26
Binary files /dev/null and b/app/assets/main/exchange.png differ
diff --git a/app/assets/main/graph.png b/app/assets/main/graph.png
new file mode 100644
index 0000000..1627297
Binary files /dev/null and b/app/assets/main/graph.png differ
diff --git a/app/assets/main/trade2.jpg b/app/assets/main/trade2.jpg
new file mode 100644
index 0000000..e5ac8f9
Binary files /dev/null and b/app/assets/main/trade2.jpg differ
diff --git a/app/assets/stylesheets/about.css.scss b/app/assets/stylesheets/about.css.scss
new file mode 100644
index 0000000..3ff4b57
--- /dev/null
+++ b/app/assets/stylesheets/about.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the About controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss
new file mode 100644
index 0000000..3b9760c
--- /dev/null
+++ b/app/assets/stylesheets/application.css.scss
@@ -0,0 +1,14 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
+ * compiled file, but it's generally better to create a new file per style scope.
+ *
+ *= require_self
+ *= require_tree .
+ */
+
diff --git a/app/assets/stylesheets/framework_and_overrides.css.scss b/app/assets/stylesheets/framework_and_overrides.css.scss
new file mode 100644
index 0000000..b6a48f2
--- /dev/null
+++ b/app/assets/stylesheets/framework_and_overrides.css.scss
@@ -0,0 +1,62 @@
+// import the CSS framework
+@import "bootstrap";
+
+// make all images responsive by default
+img {
+ @extend .img-responsive;
+ margin: 0 auto;
+ }
+// override for the 'Home' navigation link
+.navbar-brand {
+ font-size: inherit;
+ }
+
+// THESE ARE EXAMPLES YOU CAN MODIFY
+// create your own classes
+// to make views framework-neutral
+.column {
+ @extend .col-md-6;
+ @extend .text-center;
+ }
+.form {
+ @extend .col-md-6;
+ }
+.form-centered {
+ @extend .col-md-6;
+ @extend .text-center;
+ }
+.submit {
+ @extend .btn;
+ @extend .btn-primary;
+ }
+.alert {
+ margin-top: 50px;
+}
+// apply styles to HTML elements
+// to make views framework-neutral
+main {
+ @extend .container;
+ background-color: #eee;
+ padding-bottom: 80px;
+ width: 100%;
+ margin-top: 51px; // accommodate the navbar
+ }
+section {
+ @extend .row;
+ margin-top: 20px;
+ }
+h1 {
+ padding-left: 10px;
+ margin-top: 50px;
+ margin-bottom: 30px;
+}
+
+h2 {
+ margin-bottom: 25px;
+}
+
+.text {
+ width: 650px;
+ padding: 20px;
+ background-color:#FBFBEF;
+}
diff --git a/app/assets/stylesheets/main.css.scss b/app/assets/stylesheets/main.css.scss
new file mode 100644
index 0000000..e0b5279
--- /dev/null
+++ b/app/assets/stylesheets/main.css.scss
@@ -0,0 +1,148 @@
+body {
+ background-color: #f2f2f2;
+ font-family: 'Lato', sans-serif;
+ font-weight: 300;
+ font-size: 16px;
+ color: #555;
+
+ -webkit-font-smoothing: antialiased;
+ -webkit-overflow-scrolling: touch;
+}
+
+/* Titles */
+h1, h2, h3, h4, h5, h6 {
+ font-family: 'Lato', sans-serif;
+ font-weight: 300;
+ color: #333;
+}
+
+h1 {
+ font-size: 40px;
+}
+
+h3 {
+ color: #95a5a6;
+ font-weight: 400;
+}
+
+h4 {
+ color: #95a5a6;
+ font-weight: 400;
+ font-size: 20px;
+}
+
+/* Paragraph & Typographic */
+p {
+ line-height: 28px;
+ margin-bottom: 25px;
+ font-size: 16px;
+}
+
+.centered {
+ text-align: center;
+}
+
+/* Links */
+a {
+ color: #3498db;
+ word-wrap: break-word;
+
+ -webkit-transition: color 0.1s ease-in, background 0.1s ease-in;
+ -moz-transition: color 0.1s ease-in, background 0.1s ease-in;
+ -ms-transition: color 0.1s ease-in, background 0.1s ease-in;
+ -o-transition: color 0.1s ease-in, background 0.1s ease-in;
+ transition: color 0.1s ease-in, background 0.1s ease-in;
+}
+
+a:hover,
+a:focus {
+ color: #7b7b7b;
+ text-decoration: none;
+ outline: 0;
+}
+
+a:before,
+a:after {
+ -webkit-transition: color 0.1s ease-in, background 0.1s ease-in;
+ -moz-transition: color 0.1s ease-in, background 0.1s ease-in;
+ -ms-transition: color 0.1s ease-in, background 0.1s ease-in;
+ -o-transition: color 0.1s ease-in, background 0.1s ease-in;
+ transition: color 0.1s ease-in, background 0.1s ease-in;
+}
+
+ hr {
+ display: block;
+ height: 1px;
+ border: 0;
+ border-top: 1px solid #ccc;
+ margin: 1em 0;
+ padding: 0;
+}
+
+.navbar-default {
+ background-color: #3498db;
+ border-color: transparent;
+}
+
+.navbar-default .navbar-brand {
+ color: white;
+}
+
+.navbar-default .navbar-nav > li > a {
+ color: white;
+}
+
+/* Helpers */
+
+.mt {
+
+ margin-top: 100px;
+ margin-bottom: 40px;
+}
+
+.form-control {
+ height: 42px;
+ font-size: 18px;
+ width: 280px;
+}
+
+.moremargin {
+ margin-top: 5px;
+}
+
+i {
+ margin: 8px;
+ color: #3498db;
+}
+
+
+/* HeaderWrap */
+#headerwrap {
+ /* background: url(../img/bg01.jpg) no-repeat center top; */
+ background-color: #3498db;
+ margin-top: -20px;
+ padding-top:200px;
+ background-attachment: relative;
+ background-position: center center;
+ min-height: 650px;
+ width: 100%;
+
+ -webkit-background-size: 100%;
+ -moz-background-size: 100%;
+ -o-background-size: 100%;
+ background-size: 100%;
+
+ -webkit-background-size: cover;
+ -moz-background-size: cover;
+ -o-background-size: cover;
+ background-size: cover;
+}
+
+#headerwrap h1 {
+ margin-top: 60px;
+ margin-bottom: 15px;
+ color: white;
+ font-size: 45px;
+ font-weight: 300;
+ letter-spacing: 1px;
+}
\ No newline at end of file
diff --git a/app/assets/stylesheets/trade.css.scss b/app/assets/stylesheets/trade.css.scss
new file mode 100644
index 0000000..7624067
--- /dev/null
+++ b/app/assets/stylesheets/trade.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Trade controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb
new file mode 100644
index 0000000..8a3df45
--- /dev/null
+++ b/app/controllers/about_controller.rb
@@ -0,0 +1,2 @@
+class AboutController < PublicController
+end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
new file mode 100644
index 0000000..c72461b
--- /dev/null
+++ b/app/controllers/application_controller.rb
@@ -0,0 +1,37 @@
+class ApplicationController < ActionController::Base
+ # Prevent CSRF attacks by raising an exception.
+ # For APIs, you may want to use :null_session instead.
+ protect_from_forgery with: :exception
+ before_action :authorize, :init_ticker
+
+ protected
+ def authorize
+ #falls keine Session vorhanden ist, wird man wieder auf die Mainseite weitergeleitet
+ if @credentials = session[:bcmaster]
+ @trade = Btce::Trade.new(@credentials[:apikey], @credentials[:secret])
+ if (info = @trade.getInfo) && info["success"] == 1
+ @rights = info["return"]["rights"]
+ @info = info["return"]["funds"].select{
+ |currency, amount| amount != 0 || currency == "usd" || currency == "btc"
+ }.map{|currency, amount| currency + ": " + amount.to_s }.reduce{|a,b| a+" "+b}
+ else
+ flash.now[:error] = (info && info["error"]) || "something failed"
+ end
+ else
+ if is_a?(PrivateController)
+ flash.now[:notice] = "sign in first"
+ return redirect_to root_url
+ end
+ end
+ end
+ def init_ticker
+ #holen der Kursinformationen von BTC-e
+ btce_ticker = Btce::Info.new.ticker("btc_usd")
+ @btce_buy
+ @btce_sell
+ if btce_ticker
+ @btce_buy = btce_ticker["ticker"]["buy"]
+ @btce_sell = btce_ticker["ticker"]["sell"]
+ end
+ end
+end
diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb
new file mode 100644
index 0000000..c07cc93
--- /dev/null
+++ b/app/controllers/main_controller.rb
@@ -0,0 +1,30 @@
+class MainController < PublicController
+ def login
+ #Überprüfung der Verfügbarkeit des APIs
+ if (apikey = params[:apikey]) && (secret = params[:secret])
+ trade = Btce::Trade.new(apikey, secret).getInfo
+ #Überprüfung der Zugangsdaten
+ if trade && trade["success"] == 1
+ init_session(apikey, secret)
+ return redirect_to open_orders_url
+ end
+ end
+ flash.now[:error] = (trade && trade["error"]) || "apikey or password missing"
+ redirect_to root_url
+ end
+
+ def logout
+ reset_session
+ flash.now[:notice] = "logged out"
+ redirect_to root_url
+ end
+
+ private
+ def init_session(key,secret)
+ #zu implementieren: Verschlüsselung des secret keys, bevor der Key in die Session gespeichert wird
+ session[:bcmaster] = {apikey: key, secret: secret}
+ end
+ def login_params
+ params.require(:login, :password)
+ end
+end
diff --git a/app/controllers/private_controller.rb b/app/controllers/private_controller.rb
new file mode 100644
index 0000000..d9ccbb3
--- /dev/null
+++ b/app/controllers/private_controller.rb
@@ -0,0 +1,2 @@
+class PrivateController < ApplicationController
+end
\ No newline at end of file
diff --git a/app/controllers/public_controller.rb b/app/controllers/public_controller.rb
new file mode 100644
index 0000000..2857026
--- /dev/null
+++ b/app/controllers/public_controller.rb
@@ -0,0 +1,2 @@
+class PublicController < ApplicationController
+end
diff --git a/app/controllers/trade_controller.rb b/app/controllers/trade_controller.rb
new file mode 100644
index 0000000..5b55eda
--- /dev/null
+++ b/app/controllers/trade_controller.rb
@@ -0,0 +1,55 @@
+class TradeController < PrivateController
+
+ def open_orders
+ @title = "Open Orders"
+ default_action(@trade.ActiveOrders)
+ end
+
+ def transaction_history
+ @title = "Transaction History"
+ default_action(@trade.TransHistory)
+ end
+
+ def trade_history
+ @title = "Trade History"
+ default_action(@trade.TradeHistory)
+ end
+
+ def create_order
+ flash_no_trade_permission && return
+ if params[:commit]
+ if (result = @trade.Trade(order_params))["success"] == 1
+ flash.now[:notice] = result
+ return redirect_to open_orders_url
+ else
+ flash.now[:error] = result && result["error"] || "all fields are required"
+ end
+ end
+ end
+
+ protected
+ def default_action(result)
+ @table = {}
+ if result && result["success"] == 1
+ @table[:collection] = result["return"].map{ |key, value|
+ value["id"] = key
+ # Convert Unix time to UTC
+ value.each{ |a,b| value[a] = Time.at(b).gmtime if a.include? "timestamp" }
+ }
+ @table[:columns] = @table[:collection][0].map{ |key, value|
+ {name: key, display_name: Btce::API::PARAMETER_DISPLAY_NAME[key]}
+ }
+ else
+ flash.now[:error] = (result && result["error"]) || "something failed"
+ end
+ render :index
+ end
+
+ private
+ def order_params
+ params.permit(:pair, :type, :rate, :amount)
+ end
+ def flash_no_trade_permission
+ flash.now[:error] = "api-key does not have trade permission" if @rights && @rights["trade"] != 1
+ end
+end
diff --git a/app/helpers/about_helper.rb b/app/helpers/about_helper.rb
new file mode 100644
index 0000000..68e69ae
--- /dev/null
+++ b/app/helpers/about_helper.rb
@@ -0,0 +1,2 @@
+module AboutHelper
+end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
new file mode 100644
index 0000000..cf7ce84
--- /dev/null
+++ b/app/helpers/application_helper.rb
@@ -0,0 +1,26 @@
+module ApplicationHelper
+ def cp(path)
+ "active" if current_page?(path)
+ end
+
+ # http://stackoverflow.com/questions/3863844/rails-how-to-build-table-in-helper-using-content-tag
+ def display_standard_table(columns, collection)
+ return unless columns
+ collection = collection || {}
+ thead = content_tag :thead do
+ content_tag :tr do
+ columns.collect {|column| concat content_tag(:th,column[:display_name])}.join.html_safe
+ end
+ end
+ tbody = content_tag :tbody do
+ collection.collect { |elem|
+ content_tag :tr do
+ columns.collect { |column|
+ concat content_tag(:td, elem[column[:name]])
+ }.to_s.html_safe
+ end
+ }.join.html_safe
+ end
+ content_tag :table, thead.concat(tbody), class: "table table-striped table-condensed"
+ end
+end
diff --git a/app/helpers/main_helper.rb b/app/helpers/main_helper.rb
new file mode 100644
index 0000000..826effe
--- /dev/null
+++ b/app/helpers/main_helper.rb
@@ -0,0 +1,2 @@
+module MainHelper
+end
diff --git a/app/helpers/trade_helper.rb b/app/helpers/trade_helper.rb
new file mode 100644
index 0000000..ff38de1
--- /dev/null
+++ b/app/helpers/trade_helper.rb
@@ -0,0 +1,2 @@
+module TradeHelper
+end
diff --git a/app/mailers/.keep b/app/mailers/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/app/models/.keep b/app/models/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/app/models/api.rb b/app/models/api.rb
new file mode 100644
index 0000000..b9c3cb2
--- /dev/null
+++ b/app/models/api.rb
@@ -0,0 +1,3 @@
+class API
+
+end
\ No newline at end of file
diff --git a/app/models/bitstamp/api.rb b/app/models/bitstamp/api.rb
new file mode 100644
index 0000000..17187be
--- /dev/null
+++ b/app/models/bitstamp/api.rb
@@ -0,0 +1,9 @@
+module Bitstamp
+ class API
+ # https://www.bitstamp.net/api/
+ DOMAIN = "www.bitstamp.net"
+ def api_methods
+ self.class.instance_methods(false)
+ end
+ end
+end
diff --git a/app/models/bitstamp/public.rb b/app/models/bitstamp/public.rb
new file mode 100644
index 0000000..4455ced
--- /dev/null
+++ b/app/models/bitstamp/public.rb
@@ -0,0 +1,29 @@
+require "net/http"
+require "uri"
+require "json"
+
+module Bitstamp
+ class Public < API
+ %w(ticker order_book transactions eur_usd).each do |method|
+ define_method(method.to_s) do |options={}|
+ data = options.map{ |x,v| "#{x}=#{v}" }.reduce{|x,v| "#{x}{v}" }
+ get_https(data, method)
+ end
+ end
+
+ private
+
+ def build_url(method, pair)
+ "https://#{API::DOMAIN}/api/#{method}/"
+ end
+ def get_https(pair, method)
+ uri = URI.parse(build_url(method, pair))
+ begin
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) {
+ |req| JSON.parse(req.get(uri.request_uri).body) }
+ rescue
+ nil
+ end
+ end
+ end
+end
diff --git a/app/models/btce/api.rb b/app/models/btce/api.rb
new file mode 100644
index 0000000..5ada132
--- /dev/null
+++ b/app/models/btce/api.rb
@@ -0,0 +1,28 @@
+module Btce
+ class API
+ # https://hdbtce.kayako.com/Knowledgebase/List/Index/4/api
+ DOMAIN = "btc-e.com"
+ CURRENCY_PAIRS = %w(
+ btc_usd btc_eur btc_rur eur_usd ftc_btc
+ ltc_btc ltc_eur ltc_rur ltc_usd nmc_btc
+ nmc_usd nvc_btc nvc_usd ppc_btc ppc_usd
+ trc_btc usd_rur xpm_btc)
+ CURRENCIES = CURRENCY_PAIRS.map {|pair| pair.split("_")}.flatten.uniq.sort
+ PARAMETER_DISPLAY_NAME = {
+ "pair" => "Pair",
+ "type" => "Type",
+ "amount" => "Amount",
+ "rate" => "Rate",
+ "timestamp_created" => "Created",
+ "status" => "Status",
+ "id" => "id",
+ "currency" => "Currency",
+ "desc" => "Description",
+ "timestamp" => "Timestamp",
+ "order_id" => "OrderID",
+ "is_your_order" => "your order" }
+ def api_methods
+ self.class.instance_methods(false)
+ end
+ end
+end
diff --git a/app/models/btce/drive.rb b/app/models/btce/drive.rb
new file mode 100644
index 0000000..154c8b3
--- /dev/null
+++ b/app/models/btce/drive.rb
@@ -0,0 +1,38 @@
+require "net/http"
+require "uri"
+require "json"
+
+module Btce
+ class Drive
+ def initialize(url, key, secret)
+ @key = key
+ @secret = secret
+ @uri = URI.parse(url)
+ @nonce = Time.now.to_i
+ end
+ def connect(method, data)
+ data[:nonce] = (@nonce += 1)
+ data[:method] = method
+ send_data = data.map{ |x,v| "#{x}=#{v}" }.reduce{|x,v| "#{x}{v}" }
+ headers = {}
+ headers['Key'] = @key
+ headers['Sign'] = hmac(send_data)
+ JSON.parse post_https(@uri.host, @uri.port, "/tapi", send_data, headers)
+ end
+
+ private
+
+ def hmac(data)
+ sha = OpenSSL::Digest.new('sha512')
+ OpenSSL::HMAC.hexdigest(sha, @secret, data)
+ end
+ def post_https(uri, port, url, send_data, headers)
+ begin
+ Net::HTTP.start(uri, port, use_ssl: true) {
+ |req| req.post(url, send_data, headers).body }
+ rescue
+ nil
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/models/btce/info.rb b/app/models/btce/info.rb
new file mode 100644
index 0000000..7d7ca7a
--- /dev/null
+++ b/app/models/btce/info.rb
@@ -0,0 +1,30 @@
+require "net/http"
+require "uri"
+require "json"
+
+module Btce
+ class Info < API
+ # Provides access to open API.
+ # https://hdbtce.kayako.com/Knowledgebase/Article/View/28/4/public-api
+ %w(ticker trades depth fee).each do |method|
+ define_method(method) do |pair|
+ get_https(pair, method)
+ end
+ end
+
+ private
+
+ def build_url(method, pair)
+ "https://#{API::DOMAIN}/api/2/#{pair}/#{method}"
+ end
+ def get_https(pair, method)
+ uri = URI.parse(build_url(method, pair))
+ begin
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) {
+ |req| JSON.parse(req.get(uri.request_uri).body) }
+ rescue
+ nil
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/models/btce/trade.rb b/app/models/btce/trade.rb
new file mode 100644
index 0000000..c425115
--- /dev/null
+++ b/app/models/btce/trade.rb
@@ -0,0 +1,19 @@
+module Btce
+ class Trade < API
+ # https://btc-e.com/api/documentation
+ def initialize(key, secret)
+ @drive = Drive.new("https://#{API::DOMAIN}", key, secret)
+ end
+
+ %w( getInfo
+ TransHistory
+ TradeHistory
+ ActiveOrders
+ Trade
+ CancelOrder ).each do |method|
+ define_method(method) do |options = {}|
+ @drive.connect(method, options)
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/app/views/about/index.html.erb b/app/views/about/index.html.erb
new file mode 100644
index 0000000..2a46f80
--- /dev/null
+++ b/app/views/about/index.html.erb
@@ -0,0 +1,5 @@
+
+
About
+
+
This website has been programmed in the context of a case study out of the subject “Methods of Programming” in the third semester of the extra-occupational study course in Computer Science at the Zurich University of Applied Sciences (ZHAW).
+
\ No newline at end of file
diff --git a/app/views/layouts/_messages.html.erb b/app/views/layouts/_messages.html.erb
new file mode 100644
index 0000000..05ea988
--- /dev/null
+++ b/app/views/layouts/_messages.html.erb
@@ -0,0 +1,9 @@
+<%# Rails flash messages styled for Bootstrap 3.0 %>
+<% flash.each do |name, msg| %>
+ <% if msg.is_a?(String) %>
+
\ No newline at end of file
diff --git a/app/views/main/index.html.erb b/app/views/main/index.html.erb
new file mode 100644
index 0000000..5be0720
--- /dev/null
+++ b/app/views/main/index.html.erb
@@ -0,0 +1,38 @@
+
diff --git a/bin/bundle b/bin/bundle
new file mode 100755
index 0000000..66e9889
--- /dev/null
+++ b/bin/bundle
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+load Gem.bin_path('bundler', 'bundle')
diff --git a/bin/rails b/bin/rails
new file mode 100755
index 0000000..728cd85
--- /dev/null
+++ b/bin/rails
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+require_relative '../config/boot'
+require 'rails/commands'
diff --git a/bin/rake b/bin/rake
new file mode 100755
index 0000000..1724048
--- /dev/null
+++ b/bin/rake
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+require_relative '../config/boot'
+require 'rake'
+Rake.application.run
diff --git a/config.ru b/config.ru
new file mode 100644
index 0000000..fd69b31
--- /dev/null
+++ b/config.ru
@@ -0,0 +1,5 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Rails.application
+
diff --git a/config/application.rb b/config/application.rb
new file mode 100644
index 0000000..6f48bab
--- /dev/null
+++ b/config/application.rb
@@ -0,0 +1,23 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+# Require the gems listed in Gemfile, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(:default, Rails.env)
+
+module BcMaster
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+ end
+end
diff --git a/config/boot.rb b/config/boot.rb
new file mode 100644
index 0000000..3596736
--- /dev/null
+++ b/config/boot.rb
@@ -0,0 +1,4 @@
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
diff --git a/config/database.yml b/config/database.yml
new file mode 100644
index 0000000..e81a53b
--- /dev/null
+++ b/config/database.yml
@@ -0,0 +1,5 @@
+test:
+ adapter: postgresql
+ database: bcmaster_test
+ username: postgres
+
diff --git a/config/environment.rb b/config/environment.rb
new file mode 100644
index 0000000..79f2083
--- /dev/null
+++ b/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the Rails application.
+require File.expand_path('../application', __FILE__)
+
+# Initialize the Rails application.
+BcMaster::Application.initialize!
diff --git a/config/environments/development.rb b/config/environments/development.rb
new file mode 100644
index 0000000..a5b343d
--- /dev/null
+++ b/config/environments/development.rb
@@ -0,0 +1,29 @@
+BcMaster::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
+ config.cache_classes = false
+
+ # Do not eager load code on boot.
+ config.eager_load = false
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send.
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger.
+ config.active_support.deprecation = :log
+
+ # Raise an error on page load if there are pending migrations
+ config.active_record.migration_error = :page_load
+
+ # Debug mode disables concatenation and preprocessing of assets.
+ # This option may cause significant delays in view rendering with a large
+ # number of complex assets.
+ config.assets.debug = true
+end
diff --git a/config/environments/production.rb b/config/environments/production.rb
new file mode 100644
index 0000000..aaf544a
--- /dev/null
+++ b/config/environments/production.rb
@@ -0,0 +1,85 @@
+BcMaster::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # Code is not reloaded between requests.
+ config.cache_classes = true
+
+ # Eager load code on boot. This eager loads most of Rails and
+ # your application in memory, allowing both thread web servers
+ # and those relying on copy on write to perform better.
+ # Rake tasks automatically ignore this option for performance.
+ config.eager_load = true
+
+ # Full error reports are disabled and caching is turned on.
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Enable Rack::Cache to put a simple HTTP cache in front of your application
+ # Add `rack-cache` to your Gemfile before enabling this.
+ # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
+ # config.action_dispatch.rack_cache = true
+
+ # For faster asset precompiles, you can partially load your application by setting
+ # config.assets.initialize_on_precompile to false in config/application.rb, though in that case
+ # templates cannot see application objects or methods. Heroku requires this to be false.
+ config.assets.initialize_on_precompile = false
+
+ # Disable Rails's static asset server (Apache or nginx will already do this).
+ config.serve_static_assets = false
+
+ # Compress JavaScripts and CSS.
+ config.assets.js_compressor = :uglifier
+ # config.assets.css_compressor = :sass
+
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
+ config.assets.compile = false
+
+ # Generate digests for assets URLs.
+ config.assets.digest = true
+
+ # Version of your assets, change this if you want to expire all your assets.
+ config.assets.version = '1.0'
+
+ # Specifies the header that your server uses for sending files.
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # Set to :debug to see everything in the log.
+ config.log_level = :info
+
+ # Prepend all log lines with the following tags.
+ # config.log_tags = [ :subdomain, :uuid ]
+
+ # Use a different logger for distributed setups.
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
+
+ # Use a different cache store in production.
+ # config.cache_store = :mem_cache_store
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
+ # config.action_controller.asset_host = "http://assets.example.com"
+
+ # Precompile additional assets.
+ # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
+ # config.assets.precompile += %w( search.js )
+
+ # Ignore bad email addresses and do not raise email delivery errors.
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation can not be found).
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners.
+ config.active_support.deprecation = :notify
+
+ # Disable automatic flushing of the log to improve performance.
+ # config.autoflush_log = false
+
+ # Use default logging formatter so that PID and timestamp are not suppressed.
+ config.log_formatter = ::Logger::Formatter.new
+end
diff --git a/config/environments/test.rb b/config/environments/test.rb
new file mode 100644
index 0000000..9be3407
--- /dev/null
+++ b/config/environments/test.rb
@@ -0,0 +1,36 @@
+BcMaster::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb.
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Do not eager load code on boot. This avoids loading your whole application
+ # just for the purpose of running a single test. If you are using a tool that
+ # preloads Rails for running tests, you may have to set it to true.
+ config.eager_load = false
+
+ # Configure static asset server for tests with Cache-Control for performance.
+ config.serve_static_assets = true
+ config.static_cache_control = "public, max-age=3600"
+
+ # Show full error reports and disable caching.
+ config.consider_all_requests_local = true
+ config.action_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates.
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment.
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Print deprecation notices to the stderr.
+ config.active_support.deprecation = :stderr
+end
diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb
new file mode 100644
index 0000000..59385cd
--- /dev/null
+++ b/config/initializers/backtrace_silencers.rb
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb
new file mode 100644
index 0000000..4a994e1
--- /dev/null
+++ b/config/initializers/filter_parameter_logging.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+# Configure sensitive parameters which will be filtered from the log file.
+Rails.application.config.filter_parameters += [:password]
diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb
new file mode 100644
index 0000000..ac033bf
--- /dev/null
+++ b/config/initializers/inflections.rb
@@ -0,0 +1,16 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format. Inflections
+# are locale specific, and you may define rules for as many different
+# locales as you wish. All of these examples are active by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
+
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections(:en) do |inflect|
+# inflect.acronym 'RESTful'
+# end
diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb
new file mode 100644
index 0000000..72aca7e
--- /dev/null
+++ b/config/initializers/mime_types.rb
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb
new file mode 100644
index 0000000..c5164cd
--- /dev/null
+++ b/config/initializers/secret_token.rb
@@ -0,0 +1,13 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key is used for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+# You can use `rake secret` to generate a secure secret key.
+
+# Make sure your secret_key_base is kept private
+# if you're sharing your code publicly.
+BcMaster::Application.config.secret_key_base = '4e102c892c1394e3f726133f799b61765335cad7ac03961707390ebd293614753fcdaea15bb4c1801e2757834203c33bc22a2821cf79d867389c7de1da9cbd9c'
+
diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb
new file mode 100644
index 0000000..1a71261
--- /dev/null
+++ b/config/initializers/session_store.rb
@@ -0,0 +1,4 @@
+# Be sure to restart your server when you modify this file.
+
+BcMaster::Application.config.session_store :cookie_store, key: '_bcMaster_session'
+
diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb
new file mode 100644
index 0000000..f0cf46f
--- /dev/null
+++ b/config/initializers/wrap_parameters.rb
@@ -0,0 +1,15 @@
+# Be sure to restart your server when you modify this file.
+
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
+end
+
+# To enable root element in JSON for ActiveRecord objects.
+# ActiveSupport.on_load(:active_record) do
+# self.include_root_in_json = true
+# end
+
diff --git a/config/locales/en.yml b/config/locales/en.yml
new file mode 100644
index 0000000..0653957
--- /dev/null
+++ b/config/locales/en.yml
@@ -0,0 +1,23 @@
+# Files in the config/locales directory are used for internationalization
+# and are automatically loaded by Rails. If you want to use locales other
+# than English, add the necessary files in this directory.
+#
+# To use the locales, use `I18n.t`:
+#
+# I18n.t 'hello'
+#
+# In views, this is aliased to just `t`:
+#
+# <%= t('hello') %>
+#
+# To use a different locale, set it with `I18n.locale`:
+#
+# I18n.locale = :es
+#
+# This would use the information in config/locales/es.yml.
+#
+# To learn more, please read the Rails Internationalization guide
+# available at http://guides.rubyonrails.org/i18n.html.
+
+en:
+ hello: "Hello world"
diff --git a/config/routes.rb b/config/routes.rb
new file mode 100644
index 0000000..29e387f
--- /dev/null
+++ b/config/routes.rb
@@ -0,0 +1,69 @@
+BcMaster::Application.routes.draw do
+ get "about/index", as: "about"
+ get "main/index"
+ get "main/logout", as: "logout"
+ get "trade/trade_history", as: "trade_history"
+ get "trade/transaction_history", as: "transaction_history"
+ get "trade/open_orders", as: "open_orders"
+ get "trade/create_order", as: "create_order"
+
+ root :to => 'main#index'
+
+ # catchall route
+ match ':controller(/:action(/:id(.:format)))', via: [:get, :post]
+
+ # The priority is based upon order of creation: first created -> highest priority.
+ # See how all your routes lay out with "rake routes".
+
+ # You can have the root of your site routed with "root"
+ # root 'welcome#index'
+
+ # Example of regular route:
+ # get 'products/:id' => 'catalog#view'
+
+ # Example of named route that can be invoked with purchase_url(id: product.id)
+ # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
+
+ # Example resource route (maps HTTP verbs to controller actions automatically):
+ # resources :products
+
+ # Example resource route with options:
+ # resources :products do
+ # member do
+ # get 'short'
+ # post 'toggle'
+ # end
+ #
+ # collection do
+ # get 'sold'
+ # end
+ # end
+
+ # Example resource route with sub-resources:
+ # resources :products do
+ # resources :comments, :sales
+ # resource :seller
+ # end
+
+ # Example resource route with more complex sub-resources:
+ # resources :products do
+ # resources :comments
+ # resources :sales do
+ # get 'recent', on: :collection
+ # end
+ # end
+
+ # Example resource route with concerns:
+ # concern :toggleable do
+ # post 'toggle'
+ # end
+ # resources :posts, concerns: :toggleable
+ # resources :photos, concerns: :toggleable
+
+ # Example resource route within a namespace:
+ # namespace :admin do
+ # # Directs /admin/products/* to Admin::ProductsController
+ # # (app/controllers/admin/products_controller.rb)
+ # resources :products
+ # end
+end
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 0000000..294a0b1
--- /dev/null
+++ b/db/schema.rb
@@ -0,0 +1,28 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 20131214135737) do
+
+ # These are extensions that must be enabled in order to support this database
+ enable_extension "plpgsql"
+
+ create_table "users", force: true do |t|
+ t.string "name"
+ t.string "email"
+ t.string "key"
+ t.string "secret"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
diff --git a/db/seeds.rb b/db/seeds.rb
new file mode 100644
index 0000000..4edb1e8
--- /dev/null
+++ b/db/seeds.rb
@@ -0,0 +1,7 @@
+# This file should contain all the record creation needed to seed the database with its default values.
+# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
+#
+# Examples:
+#
+# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
+# Mayor.create(name: 'Emanuel', city: cities.first)
diff --git a/lib/assets/.keep b/lib/assets/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/lib/password.rb b/lib/password.rb
new file mode 100644
index 0000000..c564eb6
--- /dev/null
+++ b/lib/password.rb
@@ -0,0 +1,55 @@
+
+
+require 'digest/sha2'
+
+# This module contains functions for hashing and storing passwords
+module Password
+
+ # Generates a new salt and rehashes the password
+ def Password.update(password)
+ salt = self.salt
+ hash = self.hash(password,salt)
+ self.store(hash, salt)
+ end
+
+ # Checks the password against the stored password
+ def Password.check(password, store)
+ hash = self.get_hash(store)
+ salt = self.get_salt(store)
+ if self.hash(password,salt) == hash
+ true
+ else
+ false
+ end
+ end
+
+ protected
+
+ # Generates a psuedo-random 64 character string
+
+ def Password.salt
+ salt
+ 64.times { salt << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
+ salt
+ end
+
+ # Generates a 128 character hash
+ def Password.hash(password,salt)
+ Digest::SHA512.hexdigest("#{password}:#{salt}")
+ end
+
+ # Mixes the hash and salt together for storage
+ def Password.store(hash, salt)
+ hash + salt
+ end
+
+ # Gets the hash from a stored password
+ def Password.get_hash(store)
+ store[0..127]
+ end
+
+ # Gets the salt from a stored password
+ def Password.get_salt(store)
+ store[128..192]
+ end
+end
diff --git a/lib/tasks/.keep b/lib/tasks/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/log/.keep b/log/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/public/404.html b/public/404.html
new file mode 100644
index 0000000..a0daa0c
--- /dev/null
+++ b/public/404.html
@@ -0,0 +1,58 @@
+
+
+
+ The page you were looking for doesn't exist (404)
+
+
+
+
+
+
+
The page you were looking for doesn't exist.
+
You may have mistyped the address or the page may have moved.
+
+
If you are the application owner check the logs for more information.
+
+
diff --git a/public/422.html b/public/422.html
new file mode 100644
index 0000000..fbb4b84
--- /dev/null
+++ b/public/422.html
@@ -0,0 +1,58 @@
+
+
+
+ The change you wanted was rejected (422)
+
+
+
+
+
+
+
The change you wanted was rejected.
+
Maybe you tried to change something you didn't have access to.
+
+
If you are the application owner check the logs for more information.
+
+
diff --git a/public/500.html b/public/500.html
new file mode 100644
index 0000000..e9052d3
--- /dev/null
+++ b/public/500.html
@@ -0,0 +1,57 @@
+
+
+
+ We're sorry, but something went wrong (500)
+
+
+
+
+
+
+
We're sorry, but something went wrong.
+
+
If you are the application owner check the logs for more information.
+
+
diff --git a/public/favicon.ico b/public/favicon.ico
new file mode 100644
index 0000000..e69de29
diff --git a/public/robots.txt b/public/robots.txt
new file mode 100644
index 0000000..1a3a5e4
--- /dev/null
+++ b/public/robots.txt
@@ -0,0 +1,5 @@
+# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
+#
+# To ban all spiders from the entire site uncomment the next two lines:
+# User-agent: *
+# Disallow: /
diff --git a/test/controllers/.keep b/test/controllers/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/test/controllers/about_controller_test.rb b/test/controllers/about_controller_test.rb
new file mode 100644
index 0000000..78a4985
--- /dev/null
+++ b/test/controllers/about_controller_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class AboutControllerTest < ActionController::TestCase
+ test "should get index" do
+ get :index
+ assert_response :success
+ end
+
+end
diff --git a/test/controllers/main_controller_test.rb b/test/controllers/main_controller_test.rb
new file mode 100644
index 0000000..390e983
--- /dev/null
+++ b/test/controllers/main_controller_test.rb
@@ -0,0 +1,34 @@
+require 'test_helper'
+
+class MainControllerTest < ActionController::TestCase
+ test "should get index" do
+ get :index
+ assert_response :success
+ end
+ test "missing login should redirect to main" do
+ post :login
+ assert flash[:error]
+ assert_equal "apikey or password missing", flash[:error]
+ assert_redirected_to root_path
+ end
+ test "invalid login should redirect to main" do
+ post :login, {id: "login-form", apikey: "key",secret: "secret"}
+ assert flash[:error]
+ assert_not_equal "apikey or password missing", flash[:error]
+ assert_redirected_to root_path
+ end
+ test "valid login should redirect to trade" do
+ post :login, {
+ id: "login-form",
+ apikey: "YACSECCW-SXC6EV2I-CF679EYB-PQ3NKI93-PENNC1UM",
+ secret: "7876863e49c7ba7ac9dba285e9e6313e4b601aecfaab03b6c9704efa56f8f6de" }
+ assert_redirected_to open_orders_path
+ get :index
+ assert :success
+ end
+ test "should redirect to main" do
+ get :logout
+ assert flash[:notice]
+ assert_redirected_to root_path
+ end
+end
diff --git a/test/controllers/trade_controller_test.rb b/test/controllers/trade_controller_test.rb
new file mode 100644
index 0000000..e491cc4
--- /dev/null
+++ b/test/controllers/trade_controller_test.rb
@@ -0,0 +1,47 @@
+require 'test_helper'
+
+class TradeControllerTest < ActionController::TestCase
+ test "should get method" do
+ session[:bcmaster] = {
+ apikey: "YACSECCW-SXC6EV2I-CF679EYB-PQ3NKI93-PENNC1UM",
+ secret: "7876863e49c7ba7ac9dba285e9e6313e4b601aecfaab03b6c9704efa56f8f6de" }
+ %w(open_orders transaction_history trade_history index create_order).each do
+ |method| get method
+ assert_response :success
+ end
+ end
+ test "should flash error" do
+ session[:bcmaster] = {
+ apikey: "apikey",
+ secret: "secret" }
+ %w(open_orders transaction_history trade_history index create_order).each do
+ |method| get method
+ assert flash[:error]
+ assert_response :success
+ end
+ end
+ test "missing params should flash error" do
+ session[:bcmaster] = {
+ apikey: "YACSECCW-SXC6EV2I-CF679EYB-PQ3NKI93-PENNC1UM",
+ secret: "7876863e49c7ba7ac9dba285e9e6313e4b601aecfaab03b6c9704efa56f8f6de" }
+ post :create_order, {id: "trade-form", submit: "Trade"}
+ assert flash[:error]
+ end
+ test "valid order with no money should flash error" do
+ session[:bcmaster] = {
+ apikey: "YACSECCW-SXC6EV2I-CF679EYB-PQ3NKI93-PENNC1UM",
+ secret: "7876863e49c7ba7ac9dba285e9e6313e4b601aecfaab03b6c9704efa56f8f6de" }
+ post :create_order, {
+ id: "trade-form",
+ pair: "btc_usd",
+ type: "buy",
+ rate: "10",
+ amount: "10",
+ submit: "Trade" }
+ assert true
+ end
+ test "should redirect to main" do
+ get :index
+ assert_redirected_to root_path
+ end
+end
diff --git a/test/fixtures/.keep b/test/fixtures/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/test/helpers/.keep b/test/helpers/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/test/helpers/about_helper_test.rb b/test/helpers/about_helper_test.rb
new file mode 100644
index 0000000..dfabbf5
--- /dev/null
+++ b/test/helpers/about_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class AboutHelperTest < ActionView::TestCase
+end
diff --git a/test/helpers/main_helper_test.rb b/test/helpers/main_helper_test.rb
new file mode 100644
index 0000000..22da3c4
--- /dev/null
+++ b/test/helpers/main_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class MainHelperTest < ActionView::TestCase
+end
diff --git a/test/helpers/trade_helper_test.rb b/test/helpers/trade_helper_test.rb
new file mode 100644
index 0000000..8285745
--- /dev/null
+++ b/test/helpers/trade_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class TradeHelperTest < ActionView::TestCase
+end
diff --git a/test/integration/.keep b/test/integration/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/test/mailers/.keep b/test/mailers/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/test/models/.keep b/test/models/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/test/models/btce/api_test.rb b/test/models/btce/api_test.rb
new file mode 100644
index 0000000..8181f16
--- /dev/null
+++ b/test/models/btce/api_test.rb
@@ -0,0 +1,16 @@
+require 'test_helper'
+
+class APITest < ActiveSupport::TestCase
+ test "API has domain" do
+ assert Btce::API::DOMAIN
+ end
+ test "API contains currency pairs" do
+ assert Btce::API::CURRENCY_PAIRS
+ end
+ test "API contains currencies" do
+ assert Btce::API::CURRENCIES
+ end
+ test "API contains methods" do
+ assert Btce::API.new.api_methods
+ end
+end
diff --git a/test/models/btce/info_test.rb b/test/models/btce/info_test.rb
new file mode 100644
index 0000000..7f3dfab
--- /dev/null
+++ b/test/models/btce/info_test.rb
@@ -0,0 +1,38 @@
+require 'test_helper'
+
+class InfoTest < ActiveSupport::TestCase
+ def setup
+ @info = Btce::Info.new
+ end
+ def teardown
+ @info = nil
+ end
+ test "should return btc_usd ticker" do
+ ticker = @info.ticker("btc_usd")
+ assert !nil?, "result received"
+ assert !ticker['ticker'].nil?, "result contains ticker"
+ assert (ticker['ticker'].keys -
+ %w(high low avg vol vol_cur last
+ buy sell updated server_time)).empty?,
+ "attributes of ticker have not changed"
+ end
+ test "should return btc_usd trades" do
+ trades = @info.trades("btc_usd")
+ assert !nil?, "result received"
+ assert trades.is_a?(Array), "result is an array"
+ assert (trades[0].keys -
+ %w(date price amount tid price_currency item trade_type )).empty?,
+ "attributes of trades have not changed"
+ end
+ test "should return btc_usd market depth" do
+ D = @info.depth("btc_usd").keys
+ assert !nil?, "result received"
+ C = %w(bids asks)
+ assert ((D-C)+(C-D)).empty?,
+ "attributes of market depth match"
+ end
+ test "should return trade fees" do
+ fee = @info.fee("ltc_usd")
+ assert !nil?, "result received"
+ end
+end
diff --git a/test/models/btce/trade_test.rb b/test/models/btce/trade_test.rb
new file mode 100644
index 0000000..faa5e23
--- /dev/null
+++ b/test/models/btce/trade_test.rb
@@ -0,0 +1,13 @@
+require 'test_helper'
+
+class TradeTest < ActiveSupport::TestCase
+ def setup
+ @trade = Btce::Trade.new('key', 'secret')
+ end
+ def teardown
+ @info = nil
+ end
+ test "should return account info" do
+ assert_not_nil @trade.getInfo
+ end
+end
diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb
new file mode 100644
index 0000000..3fea27b
--- /dev/null
+++ b/test/performance/browsing_test.rb
@@ -0,0 +1,12 @@
+require 'test_helper'
+require 'rails/performance_test_help'
+
+class BrowsingTest < ActionDispatch::PerformanceTest
+ # Refer to the documentation for all available options
+ # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
+ # :output => 'tmp/performance', :formats => [:flat] }
+
+ def test_homepage
+ get '/'
+ end
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
new file mode 100644
index 0000000..8684e90
--- /dev/null
+++ b/test/test_helper.rb
@@ -0,0 +1,20 @@
+ENV["RAILS_ENV"] ||= "test"
+
+# Coverallas - Test Coverage
+require 'coveralls'
+Coveralls.wear! 'rails'
+
+require File.expand_path('../../config/environment', __FILE__)
+require 'rails/test_help'
+
+class ActiveSupport::TestCase
+ ActiveRecord::Migration.check_pending!
+
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
+ #
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
+ # -- they do not yet inherit this setting
+ fixtures :all
+
+ # Add more helper methods to be used by all tests here...
+end
diff --git a/vendor/assets/javascripts/.keep b/vendor/assets/javascripts/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/vendor/assets/stylesheets/.keep b/vendor/assets/stylesheets/.keep
new file mode 100644
index 0000000..e69de29