moo 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/LICENSE +19 -0
  2. data/README.mkd +96 -0
  3. data/data/moo/templates/businesscard_bottom_image_dual_column_text_landscape.xml +361 -0
  4. data/data/moo/templates/businesscard_bottom_image_single_column_text_landscape.xml +231 -0
  5. data/data/moo/templates/businesscard_bottom_image_single_column_text_portrait.xml +361 -0
  6. data/data/moo/templates/businesscard_full_details_image_landscape.xml +77 -0
  7. data/data/moo/templates/businesscard_full_details_image_portrait.xml +75 -0
  8. data/data/moo/templates/businesscard_full_image_landscape.xml +73 -0
  9. data/data/moo/templates/businesscard_full_image_portrait.xml +73 -0
  10. data/data/moo/templates/businesscard_full_text_landscape.xml +343 -0
  11. data/data/moo/templates/businesscard_full_text_portrait.xml +342 -0
  12. data/data/moo/templates/businesscard_left_image_landscape.xml +363 -0
  13. data/data/moo/templates/businesscard_right_image_landscape.xml +363 -0
  14. data/data/moo/templates/businesscard_top_image_dual_column_text_landscape.xml +361 -0
  15. data/data/moo/templates/businesscard_top_image_single_column_text_landscape.xml +231 -0
  16. data/data/moo/templates/businesscard_top_image_single_column_text_portrait.xml +361 -0
  17. data/data/moo/templates/minicard_bottom_image_landscape.xml +155 -0
  18. data/data/moo/templates/minicard_full_details_image_landscape.xml +75 -0
  19. data/data/moo/templates/minicard_full_details_image_portrait.xml +74 -0
  20. data/data/moo/templates/minicard_full_image_landscape.xml +75 -0
  21. data/data/moo/templates/minicard_full_image_portrait.xml +74 -0
  22. data/data/moo/templates/minicard_full_text_landscape.xml +221 -0
  23. data/data/moo/templates/minicard_left_image_landscape.xml +238 -0
  24. data/data/moo/templates/minicard_right_image_landscape.xml +239 -0
  25. data/data/moo/templates/minicard_top_image_landscape.xml +154 -0
  26. data/data/moo/templates/postcard_full_details_image_landscape.xml +77 -0
  27. data/data/moo/templates/postcard_full_details_image_portrait.xml +76 -0
  28. data/data/moo/templates/postcard_full_image_landscape.xml +77 -0
  29. data/data/moo/templates/postcard_full_image_portrait.xml +77 -0
  30. data/data/moo/templates/postcard_full_text_portrait.xml +76 -0
  31. data/data/moo/templates/sticker_image.xml +76 -0
  32. data/lib/moo.rb +4 -0
  33. data/lib/moo/client.rb +111 -0
  34. data/lib/moo/core_ext/object.rb +7 -0
  35. data/lib/moo/core_ext/string.rb +6 -0
  36. data/lib/moo/model.rb +20 -0
  37. data/lib/moo/model/bounding_box.rb +70 -0
  38. data/lib/moo/model/box_data.rb +38 -0
  39. data/lib/moo/model/card.rb +12 -0
  40. data/lib/moo/model/colour.rb +100 -0
  41. data/lib/moo/model/data.rb +11 -0
  42. data/lib/moo/model/fixed_image_data.rb +40 -0
  43. data/lib/moo/model/font.rb +66 -0
  44. data/lib/moo/model/image_basket.rb +21 -0
  45. data/lib/moo/model/image_basket_item.rb +88 -0
  46. data/lib/moo/model/image_data.rb +64 -0
  47. data/lib/moo/model/multi_line_text_data.rb +8 -0
  48. data/lib/moo/model/pack.rb +50 -0
  49. data/lib/moo/model/side.rb +72 -0
  50. data/lib/moo/model/template.rb +78 -0
  51. data/lib/moo/model/text_data.rb +72 -0
  52. metadata +160 -0
@@ -0,0 +1,7 @@
1
+ class Object
2
+ def complain_if_not_a(klass, error = ArgumentError)
3
+ unless self.is_a? klass
4
+ raise error, "Expected instance of '#{klass.to_s}', got a '#{self.class}'"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ class String
2
+ def uncapitalize
3
+ return '' if empty?
4
+ self[0, 1].downcase + self[1..-1]
5
+ end
6
+ end
@@ -0,0 +1,20 @@
1
+ # side data dependencies
2
+ require 'moo/model/bounding_box'
3
+ require 'moo/model/font'
4
+ require 'moo/model/colour'
5
+
6
+ # side data
7
+ require 'moo/model/data'
8
+ require 'moo/model/box_data'
9
+ require 'moo/model/fixed_image_data'
10
+ require 'moo/model/image_data'
11
+ require 'moo/model/multi_line_text_data'
12
+ require 'moo/model/text_data'
13
+
14
+ # pack model
15
+ require 'moo/model/pack'
16
+ require 'moo/model/card'
17
+ require 'moo/model/side'
18
+ require 'moo/model/template'
19
+ require 'moo/model/image_basket'
20
+ require 'moo/model/image_basket_item'
@@ -0,0 +1,70 @@
1
+ require 'json'
2
+ module Moo
3
+ module Model
4
+ class BoundingBox
5
+ attr_accessor :centre, :width, :height, :angle
6
+
7
+ def initialize
8
+ @centre = [0,0]
9
+ @width, @height, @angle = 0, 0, 0
10
+ yield self if block_given?
11
+ end
12
+
13
+ def to_json
14
+ to_hash.to_json
15
+ end
16
+
17
+ def to_hash
18
+ {
19
+ :center => {
20
+ :x => @centre[0],
21
+ :y => @centre[1]
22
+ },
23
+ :width => @width,
24
+ :height => @height,
25
+ :angle => @angle
26
+ }
27
+ end
28
+
29
+ def from_json(json)
30
+ hash = JSON.parse(json, :symbolize_names => true)
31
+ @centre = [hash[:center][:x], hash[:center][:y]]
32
+ @width = hash[:width]
33
+ @height = hash[:height]
34
+ @angle = hash[:angle]
35
+ end
36
+
37
+ def centre=value
38
+ unless value.is_a? Enumerable
39
+ raise ArgumentError, "value must be Enumerable, #{value.class} given"
40
+ end
41
+ if value.is_a? Hash
42
+ @centre = [value[:x], value[:y]]
43
+ else
44
+ @centre = value
45
+ end
46
+ end
47
+
48
+ def width=value
49
+ unless value.is_a? Numeric
50
+ raise ArgumentError, "value must be Numeric, #{value.class} given"
51
+ end
52
+ @width = value
53
+ end
54
+
55
+ def height=value
56
+ unless value.is_a? Numeric
57
+ raise ArgumentError, "value must be Numeric, #{value.class} given"
58
+ end
59
+ @height = value
60
+ end
61
+
62
+ def angle=value
63
+ unless value.is_a? Numeric
64
+ raise ArgumentError, "value must be Numeric, #{value.class} given"
65
+ end
66
+ @angle = value
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+ module Moo
3
+ module Model
4
+ class BoxData < Data
5
+ attr_reader :colour
6
+
7
+ def initialize
8
+ yield self if block_given?
9
+ end
10
+
11
+ def colour=(value)
12
+ unless value.kind_of? Colour
13
+ raise ArgumentError, "expected Colour, got '#{value.class}'"
14
+ end
15
+ @colour = value
16
+ end
17
+
18
+ def to_json
19
+ to_hash.to_json
20
+ end
21
+
22
+ def to_hash
23
+ {
24
+ :linkId => link_id,
25
+ :type => 'boxData',
26
+ :colour => colour.to_hash
27
+ }
28
+ end
29
+
30
+ def from_json json
31
+ hash = JSON.parse json, :symbolize_names => true
32
+ @link_id = hash[:linkId]
33
+ @colour = Colour.new
34
+ @colour.from_json(hash[:colour].to_json)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,12 @@
1
+ module Moo
2
+ module Model
3
+ class Card
4
+ # image and details side
5
+ attr_accessor :image_side, :details_side
6
+
7
+ def initialize
8
+ yield self if block_given?
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,100 @@
1
+ require 'json'
2
+ module Moo
3
+ module Model
4
+ class Colour
5
+ attr_accessor :type, :c, :m, :y, :k, :r, :g, :b
6
+
7
+ def initialize
8
+ yield self if block_given?
9
+ end
10
+
11
+ def type=new_type
12
+ unless ['cmyk','rgb','CMYK','RGB'].include? new_type
13
+ raise ArgumentError,
14
+ "type must be either 'cmyk' or 'rgb', '#{new_type}' given"
15
+ end
16
+ @type = new_type.upcase
17
+ end
18
+
19
+ def c=value
20
+ validate_numeric 'c', value, 0, 100.0
21
+ @c = value
22
+ end
23
+
24
+ def m=value
25
+ validate_numeric 'm', value, 0, 100.0
26
+ @m = value
27
+ end
28
+
29
+ def y=value
30
+ validate_numeric 'y', value, 0, 100.0
31
+ @y = value
32
+ end
33
+
34
+ def k=value
35
+ validate_numeric 'k', value, 0, 100.0
36
+ @k = value
37
+ end
38
+
39
+ def r=value
40
+ validate_numeric 'r', value, 0, 255
41
+ @r = value
42
+ end
43
+
44
+ def g=value
45
+ validate_numeric 'g', value, 0, 255
46
+ @g = value
47
+ end
48
+
49
+ def b=value
50
+ validate_numeric 'b', value, 0, 255
51
+ @b = value
52
+ end
53
+
54
+ def to_json
55
+ self.to_hash.to_json
56
+ end
57
+
58
+ def to_hash
59
+ if @type == 'RGB'
60
+ return {
61
+ :type => 'RGB',
62
+ :r => @r,
63
+ :g => @g,
64
+ :b => @b
65
+ }
66
+ elsif @type == 'CMYK'
67
+ return {
68
+ :type => 'CMYK',
69
+ :c => @c,
70
+ :m => @m,
71
+ :y => @y,
72
+ :k => @k
73
+ }
74
+ end
75
+ end
76
+
77
+ def from_json json
78
+ hash = JSON.parse json, :symbolize_names => true
79
+ keys = [:type]
80
+ if hash[:type] == 'RGB'
81
+ keys << :r << :g << :b
82
+ elsif hash[:type] == 'CMYK'
83
+ keys << :c << :m << :y << :k
84
+ end
85
+ keys.each { |k| send (k.to_s + '=').to_sym, hash[k] }
86
+ end
87
+
88
+ private
89
+ def validate_numeric field, value, from = -1000, to = 1000
90
+ unless value.is_a? Numeric
91
+ raise ArgumentError, "tried to set #{field} to non-numeric value"
92
+ end
93
+ unless from <= value and value <= to
94
+ raise ArgumentError, "value #{value.to_s} out of range, must be between #{from.to_s} and #{to.to_s} inclusive"
95
+ end
96
+ end
97
+
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,11 @@
1
+ module Moo
2
+ module Model
3
+ class Data
4
+ attr_accessor :link_id
5
+
6
+ def type
7
+ self.class.name.split('::')[2].uncapitalize
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ module Moo
2
+ module Model
3
+ class FixedImageData < Data
4
+ attr_reader :resource_uri
5
+
6
+ def initialize
7
+ yield self if block_given?
8
+ end
9
+
10
+ def resource_uri=value
11
+ unless value.is_a? String
12
+ raise ArgumentError, "expected String, got a #{value.class}"
13
+ end
14
+ @resource_uri = value
15
+ end
16
+
17
+ def to_json
18
+ to_hash.to_json
19
+ end
20
+
21
+ def to_hash
22
+ hash = {
23
+ type: type,
24
+ linkId: link_id
25
+ }
26
+ hash[:resourceUri] = resource_uri unless resource_uri.nil?
27
+ hash
28
+ end
29
+
30
+ def from_json json
31
+ from_hash(JSON.parse(json, :symbolize_names => true))
32
+ end
33
+
34
+ def from_hash hash
35
+ self.link_id = hash[:linkId]
36
+ self.resource_uri = hash[:resourceUri]
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,66 @@
1
+ require 'json'
2
+ module Moo
3
+ module Model
4
+ class Font
5
+ attr_accessor :family, :bold, :italic
6
+
7
+ ACCEPTED_FAMILIES = [
8
+ 'arial',
9
+ 'avantgarde',
10
+ 'bryant',
11
+ 'courier',
12
+ 'frutigerltpro',
13
+ 'georgia',
14
+ 'helv',
15
+ 'helvetica',
16
+ 'index',
17
+ 'meta',
18
+ 'officina',
19
+ 'radio',
20
+ 'router',
21
+ 'vagrounded'
22
+ ]
23
+
24
+ @@default_family = 'helvetica'
25
+
26
+ def initialize
27
+ @family = @@default_family
28
+ @bold = false
29
+ @italic = false
30
+ yield self if block_given?
31
+ end
32
+
33
+ alias_method :bold?, :bold
34
+ alias_method :italic?, :italic
35
+
36
+ def family=value
37
+ unless value.is_a? String
38
+ raise ArgumentError, "value must be a String, #{value.class} given"
39
+ end
40
+ unless ACCEPTED_FAMILIES.include? value
41
+ raise ArgumentError, "font family must be on of accepted list, '#{value}' given"
42
+ end
43
+ @family = value
44
+ end
45
+
46
+ def to_json
47
+ to_hash.to_json
48
+ end
49
+
50
+ def to_hash
51
+ {
52
+ :fontFamily => @family,
53
+ :bold => @bold,
54
+ :italic => @italic
55
+ }
56
+ end
57
+
58
+ def from_json(json)
59
+ hash = JSON.parse(json, :symbolize_names => true)
60
+ @family = hash[:fontFamily]
61
+ @bold = hash[:bold]
62
+ @italic = hash[:italic]
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,21 @@
1
+ module Moo
2
+ module Model
3
+ class ImageBasket
4
+ attr_accessor :items
5
+
6
+ def initialize
7
+ yield self if block_given?
8
+ end
9
+
10
+ def to_hash
11
+ hash = {
12
+ :items => items.map {|i| i.to_hash }
13
+ }
14
+ end
15
+
16
+ def to_json
17
+ to_hash.to_json
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,88 @@
1
+ module Moo
2
+ module Model
3
+ class ImageBasketItem
4
+ class ImageItem
5
+ attr_reader :resource_uri, :type, :width, :height, :rotation
6
+
7
+ def initialize
8
+ yield self if block_given?
9
+ end
10
+
11
+ def resource_uri=value
12
+ value.complain_if_not_a String
13
+ @resource_uri = value
14
+ end
15
+
16
+ def type=type
17
+ unless [ "thumbnail", "print", "preview" ].include? type
18
+ raise ArgumentError, "invalid type"
19
+ end
20
+ @type = type
21
+ end
22
+
23
+ def width=value
24
+ unless value.is_a? Numeric
25
+ raise ArgumentError, "value must be Numeric, #{value.class} given"
26
+ end
27
+ @width = value
28
+ end
29
+
30
+ def height=value
31
+ unless value.is_a? Numeric
32
+ raise ArgumentError, "value must be Numeric, #{value.class} given"
33
+ end
34
+ @height = value
35
+ end
36
+
37
+ def rotation=value
38
+ unless value.is_a? Numeric
39
+ raise ArgumentError, "value must be Numeric, #{value.class} given"
40
+ end
41
+ @rotation = value
42
+ end
43
+
44
+ def to_hash
45
+ hash = {
46
+ :resourceUri => resource_uri,
47
+ :type => type,
48
+ :width => width,
49
+ :height => height,
50
+ :rotation => rotation
51
+ }
52
+ end
53
+
54
+ def to_json
55
+ to_hash.to_json
56
+ end
57
+ end
58
+
59
+ attr_reader :resource_uri, :cache_id
60
+ attr_accessor :items
61
+
62
+ def initialize
63
+ yield self if block_given?
64
+ end
65
+
66
+ def resource_uri=value
67
+ value.complain_if_not_a String
68
+ @resource_uri = value
69
+ end
70
+
71
+ def cache_id=value
72
+ value.complain_if_not_a String
73
+ @cache_id = value
74
+ end
75
+
76
+ def to_hash
77
+ hash = {
78
+ :resourceUri => resource_uri,
79
+ :imageBox => nil,
80
+ :removable => true,
81
+ :croppable => true,
82
+ :cacheId => cache_id,
83
+ :imageItems => items.map {|i| i.to_hash }
84
+ }
85
+ end
86
+ end
87
+ end
88
+ end