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,76 @@
1
+
2
+ <?xml version="1.0" encoding="UTF-8"?>
3
+ <Template xmlns="http://www.moo.com/xsd/template-1.0">
4
+ <Code>postcard_full_details_image_portrait</Code>
5
+ <Version>1</Version>
6
+ <Settings>
7
+ <Units type="millimetres" />
8
+ <Origin orientation="top-left" offsetX="0" offsetY="0" />
9
+ <PrintArea>
10
+ <Width>109</Width>
11
+ <Height>152</Height>
12
+ </PrintArea>
13
+ <BleedBox>
14
+ <Centre x="54.5" y="76" />
15
+ <Width>109</Width>
16
+ <Height>152</Height>
17
+ <Angle>0</Angle>
18
+ </BleedBox>
19
+ <CutBox>
20
+ <Centre x="54.5" y="76" />
21
+ <Width>105</Width>
22
+ <Height>148</Height>
23
+ <Angle>0</Angle>
24
+ </CutBox>
25
+ <SafeAreaBox>
26
+ <!-- assume safe area matches bleed for now @ 2mm -->
27
+ <Centre x="54.5" y="76" />
28
+ <Width>101</Width>
29
+ <Height>144</Height>
30
+ <Angle>0</Angle>
31
+ </SafeAreaBox>
32
+ <RotationAngle>270</RotationAngle>
33
+ <FontSubstitutionStrategy>allLinesIfAnyNeeded</FontSubstitutionStrategy>
34
+ </Settings>
35
+ <Items>
36
+ <Box>
37
+ <LinkId>background_box</LinkId>
38
+ <ClippingBox>
39
+ <Centre x="54.5" y="76" />
40
+ <Width>109</Width>
41
+ <Height>152</Height>
42
+ <Angle>0</Angle>
43
+ </ClippingBox>
44
+ <Colour type="CMYK">
45
+ <Cyan>0</Cyan>
46
+ <Magenta>0</Magenta>
47
+ <Yellow>0</Yellow>
48
+ <Black>0</Black>
49
+ </Colour>
50
+ <Filled>true</Filled>
51
+ <Layout>
52
+ <zIndex>0</zIndex>
53
+ </Layout>
54
+ </Box>
55
+ <Image>
56
+ <LinkId>variable_image_back</LinkId>
57
+ <ClippingBox>
58
+ <Centre x="54.5" y="76" />
59
+ <Width>109</Width>
60
+ <Height>152</Height>
61
+ <Angle>0</Angle>
62
+ </ClippingBox>
63
+ <Constraints>
64
+ <TopEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true" insideSafe="true" />
65
+ <LeftEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true" insideSafe="true" />
66
+ <BottomEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true"
67
+ insideSafe="true" />
68
+ <RightEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true"
69
+ insideSafe="true" />
70
+ </Constraints>
71
+ <Layout>
72
+ <zIndex>1</zIndex>
73
+ </Layout>
74
+ </Image>
75
+ </Items>
76
+ </Template>
@@ -0,0 +1,77 @@
1
+
2
+ <?xml version="1.0" encoding="UTF-8"?>
3
+ <Template xmlns="http://www.moo.com/xsd/template-1.0">
4
+ <Code>postcard_full_image_landscape</Code>
5
+ <Version>1</Version>
6
+ <Settings>
7
+ <Units type="millimetres" />
8
+ <Origin orientation="top-left" offsetX="0" offsetY="0" />
9
+ <PrintArea>
10
+ <Width>152</Width>
11
+ <Height>109</Height>
12
+ </PrintArea>
13
+ <BleedBox>
14
+ <Centre x="76" y="54.5" />
15
+ <Width>152</Width>
16
+ <Height>109</Height>
17
+ <Angle>0</Angle>
18
+ </BleedBox>
19
+ <CutBox>
20
+ <Centre x="76" y="54.5" />
21
+ <Width>148</Width>
22
+ <Height>105</Height>
23
+ <Angle>0</Angle>
24
+ </CutBox>
25
+ <SafeAreaBox>
26
+ <!-- assume safe area matches bleed for now @ 2mm -->
27
+ <Centre x="76" y="54.5" />
28
+ <Width>144</Width>
29
+ <Height>101</Height>
30
+ <Angle>0</Angle>
31
+ </SafeAreaBox>
32
+ <RotationAngle>0</RotationAngle>
33
+ <FontSubstitutionStrategy>allLinesIfAnyNeeded</FontSubstitutionStrategy>
34
+ </Settings>
35
+ <Items>
36
+ <Box>
37
+ <LinkId>background_box</LinkId>
38
+ <ClippingBox>
39
+ <Centre x="76" y="54.5" />
40
+ <Width>152</Width>
41
+ <Height>109</Height>
42
+ <Angle>0</Angle>
43
+ </ClippingBox>
44
+ <Colour type="CMYK">
45
+ <Cyan>0</Cyan>
46
+ <Magenta>0</Magenta>
47
+ <Yellow>0</Yellow>
48
+ <Black>0</Black>
49
+ </Colour>
50
+ <Filled>true</Filled>
51
+ <Layout>
52
+ <zIndex>0</zIndex>
53
+ </Layout>
54
+ </Box>
55
+ <Image>
56
+ <LinkId>variable_image_front</LinkId>
57
+ <ClippingBox>
58
+ <Centre x="76" y="54.5" />
59
+ <Width>152</Width>
60
+ <Height>109</Height>
61
+ <Angle>0</Angle>
62
+ </ClippingBox>
63
+ <Constraints>
64
+ <TopEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true" insideSafe="true" />
65
+ <LeftEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true" insideSafe="true" />
66
+ <BottomEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true"
67
+ insideSafe="true" />
68
+ <RightEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true"
69
+ insideSafe="true" />
70
+ </Constraints>
71
+ <Layout>
72
+ <zIndex>1</zIndex>
73
+ </Layout>
74
+ </Image>
75
+ </Items>
76
+ </Template>
77
+
@@ -0,0 +1,77 @@
1
+
2
+ <?xml version="1.0" encoding="UTF-8"?>
3
+ <Template xmlns="http://www.moo.com/xsd/template-1.0">
4
+ <Code>postcard_full_image_portrait</Code>
5
+ <Version>1</Version>
6
+ <Settings>
7
+ <Units type="millimetres" />
8
+ <Origin orientation="top-left" offsetX="0" offsetY="0" />
9
+ <PrintArea>
10
+ <Width>152</Width>
11
+ <Height>109</Height>
12
+ </PrintArea>
13
+ <BleedBox>
14
+ <Centre x="76" y="54.5" />
15
+ <Width>152</Width>
16
+ <Height>109</Height>
17
+ <Angle>0</Angle>
18
+ </BleedBox>
19
+ <CutBox>
20
+ <Centre x="76" y="54.5" />
21
+ <Width>148</Width>
22
+ <Height>105</Height>
23
+ <Angle>0</Angle>
24
+ </CutBox>
25
+ <SafeAreaBox>
26
+ <!-- assume safe area matches bleed for now @ 2mm -->
27
+ <Centre x="76" y="54.5" />
28
+ <Width>144</Width>
29
+ <Height>101</Height>
30
+ <Angle>0</Angle>
31
+ </SafeAreaBox>
32
+ <RotationAngle>0</RotationAngle>
33
+ <FontSubstitutionStrategy>allLinesIfAnyNeeded</FontSubstitutionStrategy>
34
+ </Settings>
35
+ <Items>
36
+ <Box>
37
+ <LinkId>background_box</LinkId>
38
+ <ClippingBox>
39
+ <Centre x="76" y="54.5" />
40
+ <Width>152</Width>
41
+ <Height>109</Height>
42
+ <Angle>0</Angle>
43
+ </ClippingBox>
44
+ <Colour type="CMYK">
45
+ <Cyan>0</Cyan>
46
+ <Magenta>0</Magenta>
47
+ <Yellow>0</Yellow>
48
+ <Black>0</Black>
49
+ </Colour>
50
+ <Filled>true</Filled>
51
+ <Layout>
52
+ <zIndex>0</zIndex>
53
+ </Layout>
54
+ </Box>
55
+ <Image>
56
+ <LinkId>variable_image_front</LinkId>
57
+ <ClippingBox>
58
+ <Centre x="76" y="54.5" />
59
+ <Width>152</Width>
60
+ <Height>109</Height>
61
+ <Angle>0</Angle>
62
+ </ClippingBox>
63
+ <Constraints>
64
+ <TopEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true" insideSafe="true" />
65
+ <LeftEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true" insideSafe="true" />
66
+ <BottomEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true"
67
+ insideSafe="true" />
68
+ <RightEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true"
69
+ insideSafe="true" />
70
+ </Constraints>
71
+ <Layout>
72
+ <zIndex>1</zIndex>
73
+ </Layout>
74
+ </Image>
75
+ </Items>
76
+ </Template>
77
+
@@ -0,0 +1,76 @@
1
+
2
+ <?xml version="1.0" encoding="UTF-8"?>
3
+ <Template xmlns="http://www.moo.com/xsd/template-1.0">
4
+ <Code>postcard_full_text_portrait</Code>
5
+ <Version>1</Version>
6
+ <Settings>
7
+ <Units type="millimetres" />
8
+ <Origin orientation="top-left" offsetX="0" offsetY="0" />
9
+ <PrintArea>
10
+ <Width>109</Width>
11
+ <Height>152</Height>
12
+ </PrintArea>
13
+ <BleedBox>
14
+ <Centre x="54.5" y="76" />
15
+ <Width>109</Width>
16
+ <Height>152</Height>
17
+ <Angle>0</Angle>
18
+ </BleedBox>
19
+ <CutBox>
20
+ <Centre x="54.5" y="76" />
21
+ <Width>105</Width>
22
+ <Height>148</Height>
23
+ <Angle>0</Angle>
24
+ </CutBox>
25
+ <SafeAreaBox>
26
+ <!-- assume safe area matches bleed for now @ 2mm -->
27
+ <Centre x="54.5" y="76" />
28
+ <Width>101</Width>
29
+ <Height>144</Height>
30
+ <Angle>0</Angle>
31
+ </SafeAreaBox>
32
+ <RotationAngle>270</RotationAngle>
33
+ <FontSubstitutionStrategy>allLinesIfAnyNeeded</FontSubstitutionStrategy>
34
+ </Settings>
35
+ <Items>
36
+ <Box>
37
+ <LinkId>background_box</LinkId>
38
+ <ClippingBox>
39
+ <Centre x="54.5" y="76" />
40
+ <Width>109</Width>
41
+ <Height>152</Height>
42
+ <Angle>0</Angle>
43
+ </ClippingBox>
44
+ <Colour type="CMYK">
45
+ <Cyan>0</Cyan>
46
+ <Magenta>0</Magenta>
47
+ <Yellow>0</Yellow>
48
+ <Black>0</Black>
49
+ </Colour>
50
+ <Filled>true</Filled>
51
+ <Layout>
52
+ <zIndex>0</zIndex>
53
+ </Layout>
54
+ </Box>
55
+ <Image>
56
+ <LinkId>variable_image_back</LinkId>
57
+ <ClippingBox>
58
+ <Centre x="54.5" y="76" />
59
+ <Width>109</Width>
60
+ <Height>152</Height>
61
+ <Angle>0</Angle>
62
+ </ClippingBox>
63
+ <Constraints>
64
+ <TopEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true" insideSafe="true" />
65
+ <LeftEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true" insideSafe="true" />
66
+ <BottomEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true"
67
+ insideSafe="true" />
68
+ <RightEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true"
69
+ insideSafe="true" />
70
+ </Constraints>
71
+ <Layout>
72
+ <zIndex>1</zIndex>
73
+ </Layout>
74
+ </Image>
75
+ </Items>
76
+ </Template>
@@ -0,0 +1,76 @@
1
+
2
+ <?xml version="1.0" encoding="UTF-8"?>
3
+ <Template xmlns="http://www.moo.com/xsd/template-1.0">
4
+ <Code>sticker_image</Code>
5
+ <Version>1</Version>
6
+ <Settings>
7
+ <Units type="millimetres" />
8
+ <Origin orientation="top-left" offsetX="0" offsetY="0" />
9
+ <PrintArea>
10
+ <Width>24</Width>
11
+ <Height>24</Height>
12
+ </PrintArea>
13
+ <BleedBox>
14
+ <Centre x="12" y="12" />
15
+ <Width>24</Width>
16
+ <Height>24</Height>
17
+ <Angle>0</Angle>
18
+ </BleedBox>
19
+ <CutBox>
20
+ <Centre x="12" y="12" />
21
+ <Width>22</Width>
22
+ <Height>22</Height>
23
+ <Angle>0</Angle>
24
+ </CutBox>
25
+ <SafeAreaBox>
26
+ <!-- assume safe area matches bleed for now @ 1mm -->
27
+ <Centre x="12" y="12" />
28
+ <Width>20</Width>
29
+ <Height>20</Height>
30
+ <Angle>0</Angle>
31
+ </SafeAreaBox>
32
+ <RotationAngle>270</RotationAngle>
33
+ <FontSubstitutionStrategy>lineByLine</FontSubstitutionStrategy>
34
+ </Settings>
35
+ <Items>
36
+ <Image>
37
+ <LinkId>variable_image_front</LinkId>
38
+ <ClippingBox>
39
+ <Centre x="12" y="12" />
40
+ <Width>24</Width>
41
+ <Height>24</Height>
42
+ <Angle>0</Angle>
43
+ </ClippingBox>
44
+ <Constraints>
45
+ <TopEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true" insideSafe="true" />
46
+ <LeftEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true" insideSafe="true" />
47
+ <BottomEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true" insideSafe="true" />
48
+ <RightEdge outside="true" betweenBleedAndCut="true" betweenCutAndSafe="true" insideSafe="true" />
49
+ </Constraints>
50
+ <Layout>
51
+ <zIndex>1</zIndex>
52
+ </Layout>
53
+ </Image>
54
+ <FixedImage>
55
+ <LinkId>moo_rounded_corners</LinkId>
56
+ <ClippingBox>
57
+ <Centre x="12" y="12" />
58
+ <Width>24</Width>
59
+ <Height>24</Height>
60
+ <Angle>0</Angle>
61
+ </ClippingBox>
62
+ <Constraints />
63
+ <Layout>
64
+ <zIndex>100</zIndex>
65
+ </Layout>
66
+ <ImageBox>
67
+ <Centre x="12" y="12" />
68
+ <Width>24</Width>
69
+ <Height>24</Height>
70
+ <Angle>0</Angle>
71
+ </ImageBox>
72
+ <ResourceURI>assets:sticker/clips/roundrect.png</ResourceURI>
73
+ </FixedImage>
74
+ </Items>
75
+ </Template>
76
+
@@ -0,0 +1,4 @@
1
+ require 'moo/core_ext/object'
2
+ require 'moo/core_ext/string'
3
+ require 'moo/model'
4
+ require 'moo/client'
@@ -0,0 +1,111 @@
1
+ require 'oauth'
2
+ require 'net/http/post/multipart'
3
+ module Moo
4
+ class Client
5
+ attr_accessor :oauth_consumer,
6
+ :oauth_consumer_key,
7
+ :oauth_consumer_secret,
8
+ :oauth_access_token
9
+
10
+ def self.oauth_consumer_secret=(secret)
11
+ @@oauth_consumer_secret = secret
12
+ end
13
+
14
+ def self.oauth_consumer_key=(key)
15
+ @@oauth_consumer_key = key
16
+ end
17
+
18
+ def self.config
19
+ yield self if block_given?
20
+ end
21
+
22
+ def initialize(options={})
23
+ @oauth_consumer_secret = options[:oauth_consumer_secret]
24
+ @oauth_consumer_key = options[:oauth_consumer_key]
25
+
26
+ yield self if block_given?
27
+
28
+ # set key/secret to default if not set
29
+ @oauth_consumer_secret ||= @@oauth_consumer_secret
30
+ @oauth_consumer_key ||= @@oauth_consumer_key
31
+
32
+ # error if the oauth secret and key have not been set by now
33
+ unless @oauth_consumer_secret and @oauth_consumer_key
34
+ raise "Moo Client requires OAuth consumer key/secret"
35
+ end
36
+
37
+ # create the consumer
38
+ @oauth_consumer = OAuth::Consumer.new(
39
+ @oauth_consumer_key,
40
+ @oauth_consumer_secret, {
41
+ site: "https://secure.moo.com",
42
+ request_token_path: "/oauth/request_token.php",
43
+ access_token_path: "/oauth/access_token.php",
44
+ authorize_path: "/oauth/authorize.php"
45
+ })
46
+
47
+ # create the access token
48
+ if options[:oauth_access_token] and options[:oauth_access_token_secret]
49
+ @oauth_access_token = OAuth::AccessToken.new(
50
+ @oauth_consumer,
51
+ options[:oauth_access_token],
52
+ options[:oauth_access_token_secret])
53
+ end
54
+ end
55
+
56
+ def get_request_token(options)
57
+ @oauth_consumer.get_request_token(oauth_callback: options[:callback])
58
+ end
59
+
60
+ def create_pack(pack)
61
+ call({
62
+ method: "moo.pack.createPack",
63
+ product: pack.product_code.to_s,
64
+ pack: pack.to_json
65
+ })
66
+ end
67
+
68
+ def update_pack(pack_id, pack)
69
+ call({
70
+ method: "moo.pack.updatePack",
71
+ packId: pack_id,
72
+ pack: pack.to_json
73
+ })
74
+ end
75
+
76
+ def upload_image(path)
77
+ File.open(path) do |image|
78
+ params = {
79
+ method: "moo.image.uploadImage",
80
+ imageFile: UploadIO.new(image, "image/jpeg", "image.jpg")
81
+ }
82
+ request = Net::HTTP::Post::Multipart.new("/api/service/", params)
83
+ http = Net::HTTP.new("www.moo.com", 80)
84
+ response = http.start {|net| net.request(request) }
85
+ handle_response(response)
86
+ end
87
+ end
88
+
89
+ def import_image(image_url)
90
+ call({
91
+ method: "moo.image.importImage",
92
+ imageUrl: image_url
93
+ })
94
+ end
95
+
96
+ private
97
+ def call(params={})
98
+ handle_response(oauth_access_token.post(
99
+ "/api/service/", params, { "Content-Type" => "application/json" }))
100
+ end
101
+
102
+ def handle_response(response)
103
+ case response.code.to_i
104
+ when 200
105
+ JSON.parse(response.body)
106
+ else
107
+ raise RuntimeError, response.body
108
+ end
109
+ end
110
+ end
111
+ end