Skip to content

Commit

Permalink
First real commit with basic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
suchasurge committed May 20, 2011
1 parent a98c135 commit c1a28a9
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
.bundle
Gemfile.lock
pkg/*
.DS_Store
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--colour
1 change: 1 addition & 0 deletions .rvmrc
@@ -0,0 +1 @@
rvm use 1.9.2@rjiffy --create
1 change: 0 additions & 1 deletion Gemfile
@@ -1,4 +1,3 @@
source "http://rubygems.org"

# Specify your gem's dependencies in rjiffy.gemspec
gemspec
13 changes: 13 additions & 0 deletions README
@@ -0,0 +1,13 @@
### Description
#
#
# Find all boxes
api = Rjiffy::Connection.new(<token>)
boxes = api.boxes

# Find one box
box = api.find(ID)
box == Object with attributes for the box infos

# Delete a box
box.delete
11 changes: 10 additions & 1 deletion lib/rjiffy.rb
@@ -1,3 +1,12 @@
module Rjiffy
# Your code goes here...
require 'rjiffy/connection'
require 'rjiffy/box'
end

class ::Hash
def method_missing(name)
return self[name] if key? name
self.each { |k,v| return v if k.to_s.to_sym == name }
super.method_missing name
end
end
13 changes: 13 additions & 0 deletions lib/rjiffy/box.rb
@@ -0,0 +1,13 @@
class Box < Rjiffy::Connection
def initialize(hash)
hash.each do |k,v|
self.instance_variable_set("@#{k}", v) ## create and initialize an instance variable for this key/value pair
self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## create the getter that returns the instance variable
self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) ## create the setter that sets the instance variable
end
end

def delete
# TODO
end
end
22 changes: 22 additions & 0 deletions lib/rjiffy/connection.rb
@@ -0,0 +1,22 @@
module Rjiffy
class Connection
include HTTParty

API_VERSION = "v1.0"

def initialize(token)
self.class.base_uri "https://api.jiffybox.de/#{token}/#{API_VERSION}"
end

def list_boxes
response = self.class.get("/jiffyBoxes")
response["result"]
end

def find(id)
response = self.class.get("/jiffyBoxes/#{id}")
Box.new(response["result"])
end

end
end
8 changes: 6 additions & 2 deletions rjiffy.gemspec
Expand Up @@ -6,8 +6,8 @@ Gem::Specification.new do |s|
s.name = "rjiffy"
s.version = Rjiffy::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["TODO: Write your name"]
s.email = ["TODO: Write your email address"]
s.authors = ["Frank Mueller"]
s.email = ["frank@heidjer.info"]
s.homepage = ""
s.summary = %q{TODO: Write a gem summary}
s.description = %q{TODO: Write a gem description}
Expand All @@ -18,4 +18,8 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency('httparty', '>= 0.7.7')

s.add_development_dependency('rspec', '>= 2.6.0')
end
26 changes: 26 additions & 0 deletions spec/rjiffy_spec.rb
@@ -0,0 +1,26 @@
require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))

describe Rjiffy do

before(:all) do
#TODO: stub request
@connection = Rjiffy::Connection.new("sjdhakjsdhkajsdhak")
end

it "list all jiffyboxes" do
@connection.list_boxes.class.should == Hash
# test if the data are like the jiffybox api specification
end

it "find jiffybox by id" do
id = 11243
box = @connection.find(id)
box.name.should == "DeathStar"
box.class.should == Box
end

it "should delete specific jiffybox" do
# test delete
end

end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,4 @@
$:.push File.expand_path("../lib", __FILE__)
require "httparty"

require "rjiffy"

0 comments on commit c1a28a9

Please sign in to comment.