james-ruminant 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +35 -0
- data/lib/core_ext/options_struct.rb +20 -0
- data/lib/design.rb +84 -0
- data/lib/moo.rb +34 -0
- data/lib/template.xml.builder +20 -0
- data/lib/text_line.rb +12 -0
- data/spec/all.rb +4 -0
- data/spec/design_spec.rb +19 -0
- data/spec/moo_spec.rb +44 -0
- data/spec/product_spec.rb +29 -0
- data/spec/spec_helper.rb +7 -0
- metadata +78 -0
data/README
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
Ruminant
|
2
|
+
========
|
3
|
+
|
4
|
+
Installation
|
5
|
+
------------
|
6
|
+
|
7
|
+
If you've never installed a gem from github before - enter the following and you will eternally be graced by a thousand minds:
|
8
|
+
gem sources -a http://gems.github.com
|
9
|
+
|
10
|
+
Then you can install this like any other gem:
|
11
|
+
gem install james-ruminant
|
12
|
+
(Except don't just yet, as it's not done. Hang on in there)
|
13
|
+
|
14
|
+
Usage
|
15
|
+
-----
|
16
|
+
|
17
|
+
Moo.api_key = "your api key"
|
18
|
+
order = Moo::Order.new
|
19
|
+
moocard = Moo::MiniCard.new(:img => "http://farm...")
|
20
|
+
order.designs << moocard
|
21
|
+
order.to_xml
|
22
|
+
|
23
|
+
Contributors thus far
|
24
|
+
---------------------
|
25
|
+
Xenia Kingsley - Naming powers
|
26
|
+
Chris Mear - Fixing stuff, and provides the wine
|
27
|
+
Dan Webb - Wisdom
|
28
|
+
|
29
|
+
|
30
|
+
(__)
|
31
|
+
(oo)
|
32
|
+
/-------\/
|
33
|
+
/ | ||
|
34
|
+
* ||----||
|
35
|
+
~~ ~~
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OptionsStruct
|
2
|
+
def self.create(*accessors)
|
3
|
+
Class.new do
|
4
|
+
attr_accessor *accessors
|
5
|
+
include Methods
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Methods
|
10
|
+
def default_options
|
11
|
+
{}
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(options={})
|
15
|
+
default_options.merge(options).each do |name, value|
|
16
|
+
self.send("#{name}=",value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/design.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'text_line'
|
2
|
+
module Moo
|
3
|
+
class Design < OptionsStruct.create(:url, :type, :crop, :lines, :font_size)
|
4
|
+
def default_options
|
5
|
+
{
|
6
|
+
:lines => [],
|
7
|
+
:crop => 'auto',
|
8
|
+
:type => 'variable'
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def text=(content)
|
13
|
+
content.split("\n").each{|line| lines << TextLine.new(:string => line, :design => self) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def line(n)
|
17
|
+
lines[n-1]
|
18
|
+
end
|
19
|
+
|
20
|
+
[:design, :string, :font_size, :bold, :italic, :align, :font, :colour].each do |text_attribute|
|
21
|
+
class_eval %{
|
22
|
+
# Sets #{text_attribute} attribute on all text lines
|
23
|
+
def #{text_attribute}=(value)
|
24
|
+
set_attribute_on_all_lines(:#{text_attribute}, value)
|
25
|
+
end
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.disable_attributes(attributes=[])
|
30
|
+
attributes.each do |attribute|
|
31
|
+
class_eval %{
|
32
|
+
def #{attribute}=(*args)
|
33
|
+
raise DisabledAttributeError
|
34
|
+
end
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_xml(xml=Builder::XmlMarkup.new)
|
40
|
+
xml.design {
|
41
|
+
xml.image {
|
42
|
+
xml.url self.url
|
43
|
+
xml.type self.type
|
44
|
+
xml.crop {
|
45
|
+
xml.auto true
|
46
|
+
}
|
47
|
+
}
|
48
|
+
xml.text_collection {
|
49
|
+
#xml.tag! product_type {
|
50
|
+
xml.minicard {
|
51
|
+
lines.each_with_index do |line, index|
|
52
|
+
xml.text_line {
|
53
|
+
xml.id index+1
|
54
|
+
xml.string line.string
|
55
|
+
xml.bold line.bold
|
56
|
+
xml.align line.align
|
57
|
+
xml.font line.font
|
58
|
+
xml.colour line.colour
|
59
|
+
}
|
60
|
+
end
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def set_attribute_on_all_lines(attribute, value)
|
69
|
+
@lines.each{|line| line.send("#{attribute}=",value)}
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
class MiniCard < Design
|
75
|
+
disable_attributes [:font_size, :italic]
|
76
|
+
|
77
|
+
def product_type
|
78
|
+
"minicard"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class DisabledAttributeError < StandardError
|
83
|
+
end
|
84
|
+
end
|
data/lib/moo.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'core_ext/options_struct'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'builder'
|
4
|
+
require 'design'
|
5
|
+
|
6
|
+
module Moo
|
7
|
+
class Order < OptionsStruct.create(:api_key, :designs)
|
8
|
+
def api_version
|
9
|
+
0.7
|
10
|
+
end
|
11
|
+
|
12
|
+
def default_options
|
13
|
+
{
|
14
|
+
:designs => [],
|
15
|
+
:api_key => 0
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def product_type
|
20
|
+
@designs.first.product_type if @designs.first
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_xml(xml=Builder::XmlMarkup.new)
|
24
|
+
eval File.open(File.expand_path(File.dirname(__FILE__) + "/template.xml.builder")).read
|
25
|
+
xml
|
26
|
+
end
|
27
|
+
|
28
|
+
def submit
|
29
|
+
@api = API.new
|
30
|
+
@api.send_order(self)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
xml.instruct!
|
2
|
+
xml.moo("xsi:noNamespaceSchemaLocation" => "http://www.moo.com/xsd/api_0.7.xsd", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance") {
|
3
|
+
xml.request {
|
4
|
+
xml.version self.api_version
|
5
|
+
xml.api_key self.api_key
|
6
|
+
xml.call "build"
|
7
|
+
}
|
8
|
+
xml.payload{
|
9
|
+
xml.products {
|
10
|
+
xml.product {
|
11
|
+
xml.product_type self.product_type
|
12
|
+
xml.designs {
|
13
|
+
self.designs.each { |design|
|
14
|
+
design.to_xml(xml)
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
data/lib/text_line.rb
ADDED
data/spec/all.rb
ADDED
data/spec/design_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[spec_helper])
|
2
|
+
|
3
|
+
describe "a minicard" do
|
4
|
+
before :each do
|
5
|
+
@design = Moo::MiniCard.new(:url => "http://farm3.static.flickr.com/2300/2179038972_23d2a1ff40_o.jpg")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should have minicard as the type" do
|
9
|
+
@design.product_type.should == "minicard"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not support size" do
|
13
|
+
lambda{@design.font_size = 0.5}.should raise_error(Moo::DisabledAttributeError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not support italic" do
|
17
|
+
lambda{@design.italic = true}.should raise_error(Moo::DisabledAttributeError)
|
18
|
+
end
|
19
|
+
end
|
data/spec/moo_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[spec_helper])
|
2
|
+
|
3
|
+
describe "an empty moo order" do
|
4
|
+
before :each do
|
5
|
+
@moo = Moo::Order.new :api_key => "TESTAPIKEY"
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should have the appropiate header" do
|
9
|
+
@moo.to_xml.should include('<?xml version="1.0" encoding="UTF-8"?><moo xsi:noNamespaceSchemaLocation="http://www.moo.com/xsd/api_0.7.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should user MOO API version 0.7" do
|
13
|
+
@moo.to_xml.should include("<version>0.7</version>")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should include the API key" do
|
17
|
+
@moo.to_xml.should include("<api_key>TESTAPIKEY</api_key>")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should call build" do
|
21
|
+
@moo.to_xml.should include("<call>build</call>")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not contain to_s" do
|
25
|
+
@moo.to_xml.should_not include("to_s")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "a moo order with a minicard" do
|
30
|
+
before :each do
|
31
|
+
@moo = Moo::Order.new :api_key => "TESTAPIKEY"
|
32
|
+
@minicard = Moo::MiniCard.new(:url => "http://farm3.static.flickr.com/2300/2179038972_23d2a1ff40_o.jpg")
|
33
|
+
@moo.designs << @minicard
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have product type of 'minicard'" do
|
37
|
+
@moo.product_type.should == 'minicard'
|
38
|
+
@moo.to_xml.should include('<product_type>minicard</product_type>')
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should include the xml for the minicard" do
|
42
|
+
@moo.to_xml.should include(@minicard.to_xml)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[spec_helper])
|
2
|
+
|
3
|
+
describe "The Design base class" do
|
4
|
+
before :each do
|
5
|
+
@design = Moo::Design.new(:url => "http://farm3.static.flickr.com/2300/2179038972_23d2a1ff40_o.jpg")
|
6
|
+
@design.stub!(:product_type).and_return("minicard")
|
7
|
+
|
8
|
+
@design.text = "This is Line 1\nAnd this is the second line"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should include the design's photo url" do
|
12
|
+
@design.to_xml.should include("<url>http://farm3.static.flickr.com/2300/2179038972_23d2a1ff40_o.jpg</url>")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should store the text into multiple TextLines" do
|
16
|
+
@design.line(1).class.should == Moo::TextLine
|
17
|
+
@design.line(1).string.should == "This is Line 1"
|
18
|
+
@design.line(2).class.should == Moo::TextLine
|
19
|
+
@design.line(2).string.should == "And this is the second line"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be able to set an attribute on all lines" do
|
23
|
+
@design.line(1).bold.should == false
|
24
|
+
@design.line(2).bold.should == false
|
25
|
+
@design.bold = true
|
26
|
+
@design.line(1).bold.should == true
|
27
|
+
@design.line(2).bold.should == true
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: james-ruminant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Darling
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
date: 2008-07-24 00:00:00 -07:00
|
12
|
+
default_executable:
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ZenTest
|
16
|
+
version_requirement:
|
17
|
+
version_requirements: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.4.2
|
22
|
+
version:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: hoe
|
25
|
+
version_requirement:
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 1.1.7
|
31
|
+
version:
|
32
|
+
description: A ruby library to regurgitate MOO products
|
33
|
+
email: james@abscond.org
|
34
|
+
executables: []
|
35
|
+
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files: []
|
39
|
+
|
40
|
+
files:
|
41
|
+
- lib/moo.rb
|
42
|
+
- lib/design.rb
|
43
|
+
- lib/template.xml.builder
|
44
|
+
- lib/text_line.rb
|
45
|
+
- lib/core_ext/options_struct.rb
|
46
|
+
- README
|
47
|
+
has_rdoc: false
|
48
|
+
homepage: http://github.com/james/ruminant/tree/master
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">"
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 0.0.0
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.2.0
|
70
|
+
signing_key:
|
71
|
+
specification_version: 2
|
72
|
+
summary: A ruby library to regurgitate MOO products
|
73
|
+
test_files:
|
74
|
+
- spec/all.rb
|
75
|
+
- spec/design_spec.rb
|
76
|
+
- spec/moo_spec.rb
|
77
|
+
- spec/product_spec.rb
|
78
|
+
- spec/spec_helper.rb
|