rjiffy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
6
+ *.swp
7
+ coverage/*
8
+ .rvmrc
9
+ *.rbc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ree
6
+ - ruby-head
7
+ - rbx
8
+ - rbx-2.0
9
+ - jruby
10
+ env: JRUBY_OPTS=--1.9
11
+ script: "bundle exec rspec spec"
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2011 frank@heidjer.info
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/Readme.md ADDED
@@ -0,0 +1,46 @@
1
+ # Description [![Build Status](https://secure.travis-ci.org/suchasurge/rjiffy.png)](http://travis-ci.org/suchasurge/rjiffy)
2
+ Ruby Wrapper for jiffybox.de API
3
+
4
+ ## Configuration
5
+ Rjiffy::Configuration.configure do |conf|
6
+ conf.token = "somevalidapitoken"
7
+ end
8
+
9
+ ## List all backups
10
+ Rjiffy.backups
11
+
12
+ ## Find all boxes
13
+ Rjiffy::Box.all
14
+
15
+ ## Find one box
16
+ box = Rjiffy::Box.find(ID)
17
+
18
+ ## Reload a box
19
+ box.reload
20
+
21
+ ## Delete a box
22
+ box.delete
23
+ This triggers the delete process. On success the new status for the box is set to "DELETING"
24
+
25
+ ## Create a box
26
+ Rjiffy::Box.create({:name => "Test", :planid => "1", :distribution => "centos_5_6_32bit"})
27
+
28
+ ## List all plans
29
+ Rjiffy::Plan.all
30
+
31
+ ## Find a specific plan
32
+ Rjiffy::Plan.find("CloudLevel 2")
33
+ or use an id
34
+
35
+ Rjiffy::Plan.find(1)
36
+
37
+ ## List all distributions
38
+ Rjiffy::Distribution.all
39
+
40
+ ## Find a specific distribution
41
+ Rjiffy::Distribution.find("centos_5_4_64bit")
42
+
43
+ ## Todo
44
+ * Improve Error Handling
45
+ * Tweak Readme
46
+ * Implement all stuff we can do with the jiffybox API
data/lib/rjiffy.rb ADDED
@@ -0,0 +1,19 @@
1
+ module Rjiffy
2
+ require 'wrest'
3
+ require 'hashie'
4
+
5
+ class << self
6
+ def backups
7
+ Request.get_data("/backups").collect {|backup| Backup.new(backup[1])}
8
+ end
9
+ end
10
+
11
+ require 'rjiffy/configuration'
12
+ require 'rjiffy/request'
13
+ require 'rjiffy/result'
14
+ require 'rjiffy/backup'
15
+ require 'rjiffy/box'
16
+ require 'rjiffy/plan'
17
+ require 'rjiffy/distributions'
18
+ require 'rjiffy/exceptions'
19
+ end
@@ -0,0 +1,4 @@
1
+ module Rjiffy
2
+ class Backup < Hashie::Mash
3
+ end
4
+ end
data/lib/rjiffy/box.rb ADDED
@@ -0,0 +1,31 @@
1
+ module Rjiffy
2
+ class Box < Hashie::Mash
3
+ class << self
4
+ def all
5
+ Request.get_data("/jiffyBoxes").collect {|box| new(box[1])}
6
+ end
7
+
8
+ def find(id)
9
+ new(Request.get_data("/jiffyBoxes/#{id}"))
10
+ end
11
+
12
+ def create(params = {})
13
+ new(Request.post_data("/jiffyBoxes", params))
14
+ end
15
+ end
16
+
17
+ def reload
18
+ merge!(Request.get_data("/jiffyBoxes/#{id}"))
19
+ end
20
+
21
+ def delete
22
+ Request.delete_data("/jiffyBoxes/#{id}")
23
+ self.status = "DELETING"
24
+ self
25
+ end
26
+
27
+ def backups
28
+ Backup.new(Request.get_data("/backups/#{id}"))
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module Rjiffy
2
+ class Configuration
3
+
4
+ API_VERSION = "v1.0"
5
+
6
+ class << self
7
+ attr_accessor :token
8
+
9
+ def configure
10
+ yield self
11
+ end
12
+
13
+ def base_uri
14
+ "https://api.jiffybox.de/#{token}/#{API_VERSION}".to_uri
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module Rjiffy
2
+ class Distribution < Hashie::Mash
3
+ class << self
4
+ def all
5
+ Request.get_data("/distributions").collect {|distribution| new(add_id_to_result(distribution[0],distribution[1]))}
6
+ end
7
+
8
+ def find(id)
9
+ new(add_id_to_result(id, Request.get_data("/distributions/#{id}")))
10
+ end
11
+
12
+ private
13
+
14
+ def add_id_to_result(id, result)
15
+ result["id"] = id
16
+ result
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Rjiffy
2
+
3
+ class ApiResponseError < StandardError; end
4
+
5
+ end
@@ -0,0 +1,14 @@
1
+ module Rjiffy
2
+ class Plan < Hashie::Mash
3
+ class << self
4
+ def all
5
+ Request.get_data("/plans").collect {|plan| new(plan[1])}
6
+ end
7
+
8
+ def find(id_or_name)
9
+ escaped_id_or_name = URI.escape(id_or_name.to_s)
10
+ new(Request.get_data("/plans/#{escaped_id_or_name}"))
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ module Rjiffy
2
+ class Request
3
+ class << self
4
+ def get_data(url)
5
+ process_response(Configuration.base_uri[url].get.deserialize)
6
+ end
7
+
8
+ def post_data(url, params)
9
+ process_response(Configuration.base_uri[url].post_form(params).deserialize)
10
+ end
11
+
12
+ def delete_data(url)
13
+ process_response(Configuration.base_uri[url].delete.deserialize)
14
+ end
15
+
16
+ private
17
+
18
+ def process_response(response)
19
+ Result.new(response).data
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module Rjiffy
2
+ class Result
3
+ attr_accessor :data
4
+ def initialize(response)
5
+ @data = process_result(response)
6
+ end
7
+
8
+
9
+ private
10
+
11
+ def process_result(response)
12
+ unless response["result"] == false
13
+ response["result"]
14
+ else
15
+ raise ApiResponseError, response["messages"][0]["message"]
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Rjiffy
2
+ VERSION = "0.1.0"
3
+ end
data/rjiffy.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rjiffy/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rjiffy"
7
+ s.version = Rjiffy::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Frank Mueller"]
10
+ s.email = ["frank@heidjer.info"]
11
+ s.homepage = ""
12
+ s.summary = "Rjiffy"
13
+ s.description = "Ruby Wrapper for the jiffybox.de API"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency('wrest', '~> 1.4.2')
21
+ s.add_dependency('hashie', '~> 1.1.0')
22
+ s.add_dependency('i18n')
23
+ s.add_dependency('jruby-openssl') if RUBY_PLATFORM == 'java'
24
+
25
+ s.add_development_dependency('rspec', '~> 2.6.0')
26
+ s.add_development_dependency('fakeweb', '~> 1.3.0')
27
+ s.add_development_dependency('simplecov', '~> 0.4.2')
28
+ end
@@ -0,0 +1,19 @@
1
+ {
2
+ "messages": [],
3
+ "result": {
4
+ "daily": {
5
+ "id": "1234567890abcdef1234567890abcdef",
6
+ "created": 1234567890
7
+ },
8
+ "weekly": {
9
+ "id": "234567890abcdef1234567890abcdef1",
10
+ "created": 1234567890
11
+ },
12
+ "biweekly": {
13
+ "id": "34567890abcdef1234567890abcdef12",
14
+ "created": 1234567890
15
+ },
16
+ "day": 1,
17
+ "time": 1
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "messages": [],
3
+ "result": {
4
+ "12345": {
5
+ "daily": {
6
+ "id": "1234567890abcdef1234567890abcdef",
7
+ "created": 1234567890
8
+ },
9
+ "weekly": {
10
+ "id": "234567890abcdef1234567890abcdef1",
11
+ "created": 1234567890
12
+ },
13
+ "biweekly": {
14
+ "id": "34567890abcdef1234567890abcdef12",
15
+ "created": 1234567890
16
+ }
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,59 @@
1
+ {
2
+ "messages": [],
3
+ "result": {
4
+ "id": 12345,
5
+ "name": "Test",
6
+ "ips": {
7
+ "public": [
8
+ "188.93.14.176"
9
+ ],
10
+ "private": [
11
+ "10.93.14.175"
12
+ ]
13
+ },
14
+ "status": "READY",
15
+ "created": 1234567890,
16
+ "recoverymodeActive": false,
17
+ "manualBackupRunning": false,
18
+ "isBeingCopied": false,
19
+ "running": false,
20
+ "host": "vmhost-testsys-2-2-9-1",
21
+ "plan": {
22
+ "id": 2,
23
+ "name": "CloudLevel 3",
24
+ "diskSizeInMB": 81920,
25
+ "ramInMB": 2048,
26
+ "pricePerHour": 0.07,
27
+ "pricePerHourFrozen": 0.02
28
+ },
29
+ "metadata": {
30
+ "createdby": "JiffyBoxTeam"
31
+ },
32
+ "activeProfile": {
33
+ "name": "Standard",
34
+ "created": 1234567890,
35
+ "runlevel": "default",
36
+ "kernel": "xen-current",
37
+ "rootdisk": "/dev/xvda",
38
+ "rootdiskMode": "ro",
39
+ "status": "READY",
40
+ "disks": {
41
+ "xvda": {
42
+ "name": "CentOS 5.4",
43
+ "filesystem": "ext3",
44
+ "sizeInMB": 81408,
45
+ "created": 1234567890,
46
+ "status": "READY",
47
+ "distribution": "centos_5_4_32bit"
48
+ },
49
+ "xvdb": {
50
+ "name": " Swap",
51
+ "filesystem": "swap",
52
+ "sizeInMB": 512,
53
+ "created": 1234567890,
54
+ "status": "READY"
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,61 @@
1
+ {
2
+ "messages": [],
3
+ "result": {
4
+ "12345": {
5
+ "id": 12345,
6
+ "name": "Test",
7
+ "ips": {
8
+ "public": [
9
+ "188.93.14.176"
10
+ ],
11
+ "private": [
12
+ "10.93.14.175"
13
+ ]
14
+ },
15
+ "status": "READY",
16
+ "created": 1234567890,
17
+ "recoverymodeActive": false,
18
+ "manualBackupRunning": false,
19
+ "isBeingCopied": false,
20
+ "running": false,
21
+ "host": "vmhost-testsys-2-2-9-1",
22
+ "plan": {
23
+ "id": 2,
24
+ "name": "CloudLevel 3",
25
+ "diskSizeInMB": 81920,
26
+ "ramInMB": 2048,
27
+ "pricePerHour": 0.07,
28
+ "pricePerHourFrozen": 0.02
29
+ },
30
+ "metadata": {
31
+ "createdby": "JiffyBoxTeam"
32
+ },
33
+ "activeProfile": {
34
+ "name": "Standard",
35
+ "created": 1234567890,
36
+ "runlevel": "default",
37
+ "kernel": "xen-current",
38
+ "rootdisk": "/dev/xvda",
39
+ "rootdiskMode": "ro",
40
+ "status": "READY",
41
+ "disks": {
42
+ "xvda": {
43
+ "name": "CentOS 5.4",
44
+ "filesystem": "ext3",
45
+ "sizeInMB": 81408,
46
+ "created": 1234567890,
47
+ "status": "READY",
48
+ "distribution": "centos_5_4_32bit"
49
+ },
50
+ "xvdb": {
51
+ "name": " Swap",
52
+ "filesystem": "swap",
53
+ "sizeInMB": 512,
54
+ "created": 1234567890,
55
+ "status": "READY"
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "messages": [],
3
+ "result": {
4
+ "id": 12345,
5
+ "name": "Test",
6
+ "ips": {
7
+ "public": ["188.93.14.211"],
8
+ "private": ["10.93.14.211"]
9
+ },
10
+ "status": "CREATING",
11
+ "created": 1234567890,
12
+ "recoverymodeActive": false,
13
+ "manualBackupRunning": false,
14
+ "isBeingCopied": false,
15
+ "running": false,
16
+ "host": "vmhost-testsys-2-2-9-2",
17
+ "plan": {
18
+ "id":1 ,
19
+ "name": "CloudLevel 2",
20
+ "diskSizeInMB": 40960,
21
+ "ramInMB": 1024,
22
+ "pricePerHour": 0.04,
23
+ "pricePerHourFrozen": 0.01
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "messages": [],
3
+ "result": true
4
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "messages": [],
3
+ "result": {
4
+ "minDiskSizeMB": 1024,
5
+ "name": "CentOS 5.4 64-Bit",
6
+ "rootdiskMode": "ro",
7
+ "defaultKernel": "xen-current-x86_64"
8
+ }
9
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "messages": [],
3
+ "result": {
4
+ "centos_5_4_32bit": {
5
+ "minDiskSizeMB": 1024,
6
+ "name": "CentOS 5.4",
7
+ "rootdiskMode": "ro",
8
+ "defaultKernel": "xen-current"
9
+ },
10
+ "centos_5_4_64bit": {
11
+ "minDiskSizeMB": 1024,
12
+ "name": "CentOS 5.4 64-Bit",
13
+ "rootdiskMode": "ro",
14
+ "defaultKernel": "xen-current-x86_64"
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "messages": [],
3
+ "result": {}
4
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "messages": [
3
+ {
4
+ "type": "error",
5
+ "message": "Der von Ihnen uebergebene API-Token ist ungueltig."
6
+ }
7
+ ],
8
+ "result": false
9
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "messages": [],
3
+ "result": {
4
+ "id": 1,
5
+ "name": "CloudLevel 2",
6
+ "diskSizeInMB": 40960,
7
+ "ramInMB": 1024,
8
+ "pricePerHour": 0.04,
9
+ "pricePerHourFrozen": 0.01
10
+ }
11
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "messages": [],
3
+ "result": {
4
+ "6": {
5
+ "id":6,
6
+ "name":"CloudLevel 1",
7
+ "diskSizeInMB": 20480,
8
+ "ramInMB": 512,
9
+ "pricePerHour": 0.02,
10
+ "pricePerHourFrozen": 0.005
11
+ },
12
+ "1": {
13
+ "id": 1,
14
+ "name": "CloudLevel 2",
15
+ "diskSizeInMB": 40960,
16
+ "ramInMB": 1024,
17
+ "pricePerHour": 0.04,
18
+ "pricePerHourFrozen": 0.01
19
+ },
20
+ "2": {
21
+ "id": 2,
22
+ "name": "CloudLevel 3",
23
+ "diskSizeInMB": 81920,
24
+ "ramInMB": 2048,
25
+ "pricePerHour": 0.07,
26
+ "pricePerHourFrozen": 0.02
27
+ },
28
+ "3": {
29
+ "id": 3,
30
+ "name":" CloudLevel 4",
31
+ "diskSizeInMB": 122880,
32
+ "ramInMB": 4096,
33
+ "pricePerHour": 0.13,
34
+ "pricePerHourFrozen": 0.03
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ describe Rjiffy::Box do
4
+ before(:all) do
5
+ FakeWeb.register_uri(:get, Rjiffy::Configuration.base_uri["/jiffyBoxes"].to_s, :body => fixture_file("box_list.json"), :content_type => "application/json")
6
+ @id = 12345
7
+ FakeWeb.register_uri(:get, Rjiffy::Configuration.base_uri["/jiffyBoxes/#{@id}"].to_s, :body => fixture_file("box.json"), :content_type => "application/json")
8
+ FakeWeb.register_uri(:delete, Rjiffy::Configuration.base_uri["/jiffyBoxes/#{@id}"].to_s, :body => fixture_file("deleted_box.json"), :content_type => "application/json")
9
+ FakeWeb.register_uri(:get, Rjiffy::Configuration.base_uri["/backups/#{@id}"].to_s, :body => fixture_file("backup_from_box.json"), :content_type => "application/json")
10
+ FakeWeb.register_uri(:post, Rjiffy::Configuration.base_uri["/jiffyBoxes"].to_s, :body => fixture_file("created_box.json"), :content_type => "application/json")
11
+ @box = Rjiffy::Box.find(@id)
12
+ end
13
+
14
+ it "list all jiffyboxes" do
15
+ list_of_boxes = Rjiffy::Box.all
16
+ list_of_boxes.map{|box| box.class}.uniq.each do |rjiffy_box|
17
+ rjiffy_box.should == Rjiffy::Box
18
+ end
19
+ list_of_boxes.first.name.should == "Test"
20
+ end
21
+
22
+ it "find jiffybox by id" do
23
+ responded_box = Rjiffy::Box.find(@id)
24
+ responded_box.id.should == @id
25
+ responded_box.name.should == "Test"
26
+ end
27
+
28
+ it "deletes a box" do
29
+ @box.delete
30
+ @box.status.should == "DELETING"
31
+ end
32
+
33
+ it "list the backups for the box", :box_backups => true do
34
+ backups = @box.backups
35
+ backups.day.should == 1
36
+ end
37
+
38
+ it "creates a new jiffybox", :create_jiffybox => true do
39
+ params = {:name => "Test", :planid => "1", :distribution => "centos_5_6_32bit"}
40
+ box = Rjiffy::Box.create(params)
41
+ box.status.should == "CREATING"
42
+ end
43
+
44
+ it "reloads the box to update data", :reload_jiffybox => true do
45
+ box = Rjiffy::Box.create({:name => "Test", :planid => "1", :distribution => "centos_5_6_32bit"})
46
+ box.status.should == "CREATING"
47
+ box.name.should == "Test"
48
+ id_from_created_box = box.id
49
+ created_at = box.created
50
+ box.reload
51
+ box.status.should == "READY"
52
+ box.created.should == created_at
53
+ box.id.should == id_from_created_box
54
+ end
55
+
56
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rjiffy::Configuration do
4
+
5
+
6
+ it "sets the config variables and build the base_url" do
7
+ Rjiffy::Configuration.configure {|conf| conf.token = "mytoken"}
8
+ Rjiffy::Configuration.token.should == "mytoken"
9
+ Rjiffy::Configuration.base_uri.should == "https://api.jiffybox.de/mytoken/v1.0".to_uri
10
+ end
11
+
12
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rjiffy::Distribution do
4
+
5
+ it "list all available distributions" do
6
+ FakeWeb.register_uri(:get, Rjiffy::Configuration.base_uri["/distributions"].to_s, :body => fixture_file("distributions_list.json"), :content_type => "application/json")
7
+ distributions = Rjiffy::Distribution.all
8
+ distributions.count.should == 2
9
+ distributions.last.class.should == Rjiffy::Distribution
10
+ distributions.map(&:name).include?("CentOS 5.4 64-Bit").should == true
11
+ distributions.map(&:id).include?("centos_5_4_64bit").should == true
12
+ end
13
+
14
+ it "find distribution by id" do
15
+ distribution_id = "centos_5_4_64bit"
16
+ FakeWeb.register_uri(:get, Rjiffy::Configuration.base_uri["/distributions/#{distribution_id}"].to_s, :body => fixture_file("distribution.json"), :content_type => "application/json")
17
+ distribution = Rjiffy::Distribution.find(distribution_id)
18
+ distribution.id.should == distribution_id
19
+ distribution.rootdiskMode.should == "ro"
20
+ distribution.class.should == Rjiffy::Distribution
21
+ end
22
+
23
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rjiffy::Plan do
4
+ it "list all available plans" do
5
+ FakeWeb.register_uri(:get, Rjiffy::Configuration.base_uri["/plans"].to_s, :body => fixture_file("plan_list.json"), :content_type => "application/json")
6
+ plans = Rjiffy::Plan.all
7
+ plans.count.should == 4
8
+ plans.first.class.should == Rjiffy::Plan
9
+ plans.map(&:id).include?(6).should == true
10
+ plans.map(&:name).include?("CloudLevel 1").should == true
11
+ end
12
+
13
+ context "finding plans" do
14
+ before(:all) do
15
+ id = URI.escape("1")
16
+ name = URI.escape("CloudLevel 2")
17
+ FakeWeb.register_uri(:get, Rjiffy::Configuration.base_uri["/plans/#{id}"].to_s, :body => fixture_file("plan.json"), :content_type => "application/json")
18
+ FakeWeb.register_uri(:get, Rjiffy::Configuration.base_uri["/plans/#{name}"].to_s, :body => fixture_file("plan.json"), :content_type => "application/json")
19
+ end
20
+
21
+ it "by id" do
22
+ plan = Rjiffy::Plan.find(1)
23
+ plan.id.should == 1
24
+ plan.name.should == "CloudLevel 2"
25
+ end
26
+
27
+ it "by name" do
28
+ plan = Rjiffy::Plan.find("CloudLevel 2")
29
+ plan.id.should == 1
30
+ plan.name.should == "CloudLevel 2"
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rjiffy::Result do
4
+
5
+ it "raises error on failure response" do
6
+ error_response = {"messages" => [{"type" => "error", "message" => "Der von Ihnen uebergebene API-Token ist ungueltig."}],"result" => false}
7
+ expect { Rjiffy::Result.new(error_response) }.to raise_error(Rjiffy::ApiResponseError, "Der von Ihnen uebergebene API-Token ist ungueltig.")
8
+ end
9
+
10
+ it "returns the raw data from a response" do
11
+ Rjiffy::Result.new({"result" => {:test => "whatever"}}).data.class.should == Hash
12
+ Rjiffy::Result.new({"result" => true}).data.class.should == TrueClass
13
+ Rjiffy::Result.new({"result" => "whatever"}).data.class.should == String
14
+ end
15
+
16
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe Rjiffy do
4
+
5
+ describe "basic handling for jiffyboxes" do
6
+ it "handles empty results" do
7
+ FakeWeb.register_uri(:get, Rjiffy::Configuration.base_uri["/jiffyBoxes"].to_s, :body => fixture_file("empty_result.json"), :content_type => "application/json")
8
+ box_list = Rjiffy::Box.all
9
+ box_list.class.should == Array
10
+ box_list.should be_empty
11
+ end
12
+
13
+
14
+ it "list the backups for all available boxes" do
15
+ FakeWeb.register_uri(:get, Rjiffy::Configuration.base_uri["/backups"].to_s, :body => fixture_file("backup_list.json"), :content_type => "application/json")
16
+ available_backups = Rjiffy.backups
17
+ available_backups.class.should == Array
18
+ available_backups.count.should == 1
19
+ backup = available_backups.first
20
+ backup.daily.id.should == "1234567890abcdef1234567890abcdef"
21
+ backup.weekly.created == 1234567890
22
+ backup.biweekly.id == "34567890abcdef1234567890abcdef12"
23
+ end
24
+ end
25
+
26
+ describe "Errors", :handle_errors => true do
27
+ it "handles api errors in response" do
28
+ FakeWeb.register_uri(:get, Rjiffy::Configuration.base_uri["/jiffyBoxes"].to_s, :body => fixture_file("error_response.json"), :content_type => "application/json")
29
+ expect { Rjiffy::Box.all }.to raise_error(Rjiffy::ApiResponseError, "Der von Ihnen uebergebene API-Token ist ungueltig.")
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,24 @@
1
+ require 'simplecov'
2
+ SimpleCov.start if ENV["COVERAGE"]
3
+ # use with:
4
+ # COVERAGE=true rspec .
5
+
6
+ $:.push File.expand_path("../lib", __FILE__)
7
+ require 'wrest'
8
+ require 'fakeweb'
9
+
10
+ require 'rjiffy'
11
+
12
+ RSpec.configure do |config|
13
+ config.before(:all) do
14
+ Rjiffy::Configuration.configure do |conf|
15
+ conf.token = "somevalidtoken"
16
+ end
17
+ end
18
+ end
19
+
20
+ def fixture_file(filename)
21
+ return '' if filename == ''
22
+ file_path = File.expand_path(File.dirname(__FILE__) + '/../spec/fixtures/' + filename)
23
+ File.read(file_path)
24
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rjiffy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Frank Mueller
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-16 00:00:00.000000000 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: wrest
17
+ requirement: &2152117760 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.4.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2152117760
26
+ - !ruby/object:Gem::Dependency
27
+ name: hashie
28
+ requirement: &2152117260 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2152117260
37
+ - !ruby/object:Gem::Dependency
38
+ name: i18n
39
+ requirement: &2152116880 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *2152116880
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: &2152116320 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 2.6.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2152116320
59
+ - !ruby/object:Gem::Dependency
60
+ name: fakeweb
61
+ requirement: &2152115820 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 1.3.0
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2152115820
70
+ - !ruby/object:Gem::Dependency
71
+ name: simplecov
72
+ requirement: &2152115360 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.4.2
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *2152115360
81
+ description: Ruby Wrapper for the jiffybox.de API
82
+ email:
83
+ - frank@heidjer.info
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - .gitignore
89
+ - .rspec
90
+ - .travis.yml
91
+ - Gemfile
92
+ - LICENSE
93
+ - Rakefile
94
+ - Readme.md
95
+ - lib/rjiffy.rb
96
+ - lib/rjiffy/backup.rb
97
+ - lib/rjiffy/box.rb
98
+ - lib/rjiffy/configuration.rb
99
+ - lib/rjiffy/distributions.rb
100
+ - lib/rjiffy/exceptions.rb
101
+ - lib/rjiffy/plan.rb
102
+ - lib/rjiffy/request.rb
103
+ - lib/rjiffy/result.rb
104
+ - lib/rjiffy/version.rb
105
+ - rjiffy.gemspec
106
+ - spec/fixtures/backup_from_box.json
107
+ - spec/fixtures/backup_list.json
108
+ - spec/fixtures/box.json
109
+ - spec/fixtures/box_list.json
110
+ - spec/fixtures/created_box.json
111
+ - spec/fixtures/deleted_box.json
112
+ - spec/fixtures/distribution.json
113
+ - spec/fixtures/distributions_list.json
114
+ - spec/fixtures/empty_result.json
115
+ - spec/fixtures/error_response.json
116
+ - spec/fixtures/plan.json
117
+ - spec/fixtures/plan_list.json
118
+ - spec/rjiffy/box_spec.rb
119
+ - spec/rjiffy/configuration_spec.rb
120
+ - spec/rjiffy/distribution_spec.rb
121
+ - spec/rjiffy/plan_spec.rb
122
+ - spec/rjiffy/result_spec.rb
123
+ - spec/rjiffy_spec.rb
124
+ - spec/spec_helper.rb
125
+ has_rdoc: true
126
+ homepage: ''
127
+ licenses: []
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 1.6.2
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: Rjiffy
150
+ test_files:
151
+ - spec/fixtures/backup_from_box.json
152
+ - spec/fixtures/backup_list.json
153
+ - spec/fixtures/box.json
154
+ - spec/fixtures/box_list.json
155
+ - spec/fixtures/created_box.json
156
+ - spec/fixtures/deleted_box.json
157
+ - spec/fixtures/distribution.json
158
+ - spec/fixtures/distributions_list.json
159
+ - spec/fixtures/empty_result.json
160
+ - spec/fixtures/error_response.json
161
+ - spec/fixtures/plan.json
162
+ - spec/fixtures/plan_list.json
163
+ - spec/rjiffy/box_spec.rb
164
+ - spec/rjiffy/configuration_spec.rb
165
+ - spec/rjiffy/distribution_spec.rb
166
+ - spec/rjiffy/plan_spec.rb
167
+ - spec/rjiffy/result_spec.rb
168
+ - spec/rjiffy_spec.rb
169
+ - spec/spec_helper.rb