moo 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,64 @@
1
+ module Moo
2
+ module Model
3
+ class ImageData < Data
4
+ attr_reader :image_box, :resource_uri, :image_store_file_id, :enhance
5
+
6
+ def initialize
7
+ @enhance = false
8
+ yield self if block_given?
9
+ end
10
+
11
+ def image_box=value
12
+ value.complain_if_not_a BoundingBox
13
+ @image_box = value
14
+ end
15
+
16
+ def resource_uri=value
17
+ value.complain_if_not_a String
18
+ @resource_uri = value
19
+ end
20
+
21
+ def image_store_file_id=value
22
+ value.complain_if_not_a String
23
+ @image_store_file_id = value
24
+ end
25
+
26
+ def enhance=value
27
+ unless [true,false].include? value
28
+ raise ArgumentError
29
+ end
30
+ @enhance = value
31
+ end
32
+
33
+ def to_json
34
+ to_hash.to_json
35
+ end
36
+
37
+ def to_hash
38
+ hash = {
39
+ type: type,
40
+ linkId: link_id,
41
+ imageBox: image_box.to_hash,
42
+ resourceUri: resource_uri,
43
+ }
44
+ hash[:imageStoreFileId] = image_store_file_id unless image_store_file_id.nil?
45
+ hash[:enhance] = enhance
46
+ hash
47
+ end
48
+
49
+ def from_hash hash
50
+ self.link_id = hash[:linkId]
51
+ b = BoundingBox.new
52
+ b.from_json(hash[:imageBox].to_json)
53
+ self.image_box = b
54
+ self.resource_uri = hash[:resourceUri]
55
+ self.image_store_file_id = hash[:imageStoreFileId] if hash[:imageStoreFileId]
56
+ self.enhance = hash[:enhance]
57
+ end
58
+
59
+ def from_json json
60
+ from_hash(JSON.parse(json, :symbolize_names => true))
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,8 @@
1
+ require 'moo/model/text_data'
2
+
3
+ module Moo
4
+ module Model
5
+ class MultiLineTextData < TextData
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,50 @@
1
+ module Moo
2
+ module Model
3
+ class Pack
4
+ attr_accessor :cards, :sides, :product_code, :product_version, :num_cards, :image_basket
5
+
6
+ PRODUCT_CODES = ['businesscard', 'minicard', 'postcard', 'holidaycard', 'sticker'].freeze
7
+
8
+ def initialize
9
+ @cards = []
10
+ @sides = []
11
+ @product_version = 0
12
+ yield self if block_given?
13
+ end
14
+
15
+ def product_code=code
16
+ unless PRODUCT_CODES.include? code
17
+ raise(ArgumentError,
18
+ "Invalid product code '#{code}', must be one of [#{PRODUCT_CODES.join(', ')}]"
19
+ )
20
+ end
21
+ @product_code = code
22
+ end
23
+
24
+ def to_json
25
+ to_hash.to_json
26
+ end
27
+
28
+ def to_hash
29
+ hash = {
30
+ numCards: num_cards,
31
+ productCode: product_code,
32
+ productVersion: product_version,
33
+ sides: sides.map {|s| s.to_hash }
34
+ }
35
+
36
+ hash[:imageBasket] = image_basket.to_hash unless image_basket.nil?
37
+
38
+ hash
39
+ end
40
+
41
+ def fill_side_nums
42
+ counter = 1
43
+ @sides.reject {|s| s.side_num.is_a? Numeric}.each do |s|
44
+ s.side_num = counter
45
+ counter += 1
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,72 @@
1
+ require 'moo/model/template'
2
+ module Moo
3
+ module Model
4
+ class Side
5
+ attr_accessor :template, :data, :type, :pack, :side_num
6
+
7
+ def initialize
8
+ @data = []
9
+ yield self if block_given?
10
+ end
11
+
12
+ def type=new_type
13
+ unless ['image', 'details'].include? new_type
14
+ raise ArgumentError, "type must be either 'image' or 'details'"
15
+ end
16
+ @type = new_type
17
+ end
18
+
19
+ def pack=new_pack
20
+ unless new_pack.is_a? Pack
21
+ raise ArgumentError, "pack must be of type Pack, #{new_pack.class} given"
22
+ end
23
+ @pack = pack
24
+ end
25
+
26
+ # wrapper that sets template object
27
+ def template_code=code
28
+ unless Template.codes.include? code
29
+ raise ArgumentError, "invalid templatecode"
30
+ end
31
+ @template = Template.with_code code
32
+ end
33
+
34
+ def template_code
35
+ return nil if @template.nil?
36
+ @template.code
37
+ end
38
+
39
+ def to_json
40
+ to_hash.to_json
41
+ end
42
+
43
+ def to_hash
44
+ hash = {
45
+ sideNum: side_num,
46
+ templateCode: template_code,
47
+ type: type,
48
+ data: data.map { |d| d.to_hash }
49
+ }
50
+ end
51
+
52
+ def from_json json
53
+ from_hash(JSON.parse(json, :symbolize_names => true))
54
+ end
55
+
56
+ def from_hash hash
57
+ self.side_num = hash[:sideNum]
58
+ self.template_code = hash[:templateCode]
59
+ self.type = hash[:type]
60
+ self.data = hash[:data].map {|d| data_from_hash d }
61
+ end
62
+
63
+ def data_from_hash(hash)
64
+ klass = hash[:type].gsub(/\b\w/){|s|s.upcase}
65
+ data = eval(klass).new
66
+ data.from_hash hash
67
+ data
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,78 @@
1
+ require 'fileutils'
2
+ require 'nokogiri'
3
+ module Moo
4
+ module Model
5
+ class Template
6
+ class << self
7
+ attr_reader :all
8
+
9
+ # Load all the templates into objects
10
+ def load
11
+ @all = [] #contains all template objects
12
+
13
+ template_dir = Gem.datadir('moo') + '/templates/'
14
+
15
+ template_files = Dir.entries(template_dir).reject do |t|
16
+ t == '.' || t == '..'
17
+ end
18
+
19
+ template_files.each do |f|
20
+ path = template_dir + f
21
+ @all << Template.new(path)
22
+ end
23
+ end
24
+
25
+ # Discard all the template objects
26
+ def unload
27
+ @all = nil
28
+ end
29
+
30
+ # True if templates loaded, false otherwise
31
+ def loaded?
32
+ !@all.nil?
33
+ end
34
+
35
+ # all template codes
36
+ def codes
37
+ load unless loaded?
38
+ @all.map { |t| t.code }
39
+ end
40
+
41
+ def with_code(code)
42
+ load unless loaded?
43
+ @all.select { |t| t.code == code }[0]
44
+ end
45
+ end
46
+
47
+ attr_reader :filename, :product
48
+ attr_accessor :code
49
+
50
+ # get the filename, check it exists, but don't load it up
51
+ # until we need to
52
+ def initialize(template_filename)
53
+ unless File.exists? template_filename
54
+ raise ArgumentError, "Template file provided doesn't exist: #{template_filename}"
55
+ end
56
+ @filename = template_filename
57
+ @code = File.basename @filename, '.xml'
58
+ @product = @code.split('_')[0]
59
+ @xml_doc = nil
60
+ end
61
+
62
+ # load the data from the file into the object
63
+ def load
64
+ doc = Nokogiri::XML(open(filename))
65
+ xml_template_code = doc.css('Code')[0].content
66
+ unless code == xml_template_code
67
+ raise StandardError, "template codes '#{code}' and '#{xml_template_code}' don't match"
68
+ end
69
+ @xml_doc = doc
70
+ end
71
+
72
+ def to_xml
73
+ load if @xml_doc.nil?
74
+ @xml_doc.to_s
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,72 @@
1
+ require 'moo/model/font'
2
+
3
+ module Moo
4
+ module Model
5
+ class TextData < Data
6
+ attr_reader :font, :colour, :point_size, :alignment
7
+ attr_accessor :text
8
+
9
+ def initialize
10
+ yield self if block_given?
11
+ end
12
+
13
+ def font=value
14
+ unless value.kind_of? Font
15
+ raise ArgumentError, "expected Font, got '#{value.class}'"
16
+ end
17
+ @font = value
18
+ end
19
+
20
+ def colour=value
21
+ unless value.kind_of? Colour
22
+ raise ArgumentError, "expected Colour, got '#{value.class}'"
23
+ end
24
+ @colour = value
25
+ end
26
+
27
+ def point_size=value
28
+ @point_size = value
29
+ unless value.kind_of? Numeric
30
+ raise ArgumentError, "expected Numeric, got '#{value.class}'"
31
+ end
32
+ end
33
+
34
+ def alignment=value
35
+ unless [:left, :right, :center].include? value.to_sym
36
+ raise ArgumentError, "alignment must be one of :left, :right or :center"
37
+ end
38
+ @alignment = value.to_sym
39
+ end
40
+
41
+ def to_json
42
+ to_hash.to_json
43
+ end
44
+
45
+ def to_hash
46
+ hash = {
47
+ :type => type,
48
+ :linkId => link_id,
49
+ :text => text
50
+ }
51
+ hash[:pointSize] = point_size unless point_size.nil?
52
+ hash[:alignment] = alignment unless point_size.nil?
53
+ hash[:font] = font.to_hash unless font.nil?
54
+ hash[:colour] = colour.to_hash unless colour.nil?
55
+ hash
56
+ end
57
+
58
+ def from_json json
59
+ hash = JSON.parse(json, :symbolize_names => true)
60
+ self.link_id = hash[:linkId]
61
+ self.text = hash[:text]
62
+ self.point_size = hash[:pointSize]
63
+ self.alignment = hash[:alignment].to_sym
64
+ self.font = Font.new
65
+ self.font.from_json(hash[:font].to_json)
66
+ self.colour = Colour.new
67
+ self.colour.from_json(hash[:colour].to_json)
68
+ end
69
+
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Najaf Ali
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: nokogiri
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: multipart-post
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Simple ruby library for creating and printing stuff at moo.com
79
+ email:
80
+ - ali.najaf@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - lib/moo/model/multi_line_text_data.rb
86
+ - lib/moo/model/box_data.rb
87
+ - lib/moo/model/image_data.rb
88
+ - lib/moo/model/fixed_image_data.rb
89
+ - lib/moo/model/font.rb
90
+ - lib/moo/model/template.rb
91
+ - lib/moo/model/data.rb
92
+ - lib/moo/model/bounding_box.rb
93
+ - lib/moo/model/pack.rb
94
+ - lib/moo/model/text_data.rb
95
+ - lib/moo/model/image_basket_item.rb
96
+ - lib/moo/model/card.rb
97
+ - lib/moo/model/side.rb
98
+ - lib/moo/model/colour.rb
99
+ - lib/moo/model/image_basket.rb
100
+ - lib/moo/core_ext/object.rb
101
+ - lib/moo/core_ext/string.rb
102
+ - lib/moo/client.rb
103
+ - lib/moo/model.rb
104
+ - lib/moo.rb
105
+ - data/moo/templates/postcard_full_text_portrait.xml
106
+ - data/moo/templates/postcard_full_details_image_portrait.xml
107
+ - data/moo/templates/businesscard_full_details_image_landscape.xml
108
+ - data/moo/templates/minicard_full_details_image_portrait.xml
109
+ - data/moo/templates/minicard_full_image_portrait.xml
110
+ - data/moo/templates/businesscard_full_text_portrait.xml
111
+ - data/moo/templates/postcard_full_details_image_landscape.xml
112
+ - data/moo/templates/businesscard_top_image_single_column_text_landscape.xml
113
+ - data/moo/templates/businesscard_top_image_dual_column_text_landscape.xml
114
+ - data/moo/templates/minicard_left_image_landscape.xml
115
+ - data/moo/templates/businesscard_bottom_image_single_column_text_landscape.xml
116
+ - data/moo/templates/businesscard_bottom_image_dual_column_text_landscape.xml
117
+ - data/moo/templates/businesscard_full_details_image_portrait.xml
118
+ - data/moo/templates/businesscard_top_image_single_column_text_portrait.xml
119
+ - data/moo/templates/minicard_full_image_landscape.xml
120
+ - data/moo/templates/sticker_image.xml
121
+ - data/moo/templates/businesscard_full_image_landscape.xml
122
+ - data/moo/templates/postcard_full_image_portrait.xml
123
+ - data/moo/templates/minicard_right_image_landscape.xml
124
+ - data/moo/templates/businesscard_full_image_portrait.xml
125
+ - data/moo/templates/minicard_full_text_landscape.xml
126
+ - data/moo/templates/businesscard_left_image_landscape.xml
127
+ - data/moo/templates/postcard_full_image_landscape.xml
128
+ - data/moo/templates/minicard_full_details_image_landscape.xml
129
+ - data/moo/templates/businesscard_right_image_landscape.xml
130
+ - data/moo/templates/businesscard_full_text_landscape.xml
131
+ - data/moo/templates/minicard_bottom_image_landscape.xml
132
+ - data/moo/templates/businesscard_bottom_image_single_column_text_portrait.xml
133
+ - data/moo/templates/minicard_top_image_landscape.xml
134
+ - LICENSE
135
+ - README.mkd
136
+ homepage: http://github.com/Najaf/moo.rb
137
+ licenses: []
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: 1.3.6
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 1.8.21
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: Moo API client library
160
+ test_files: []