ravelry 0.0.1

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 (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/.yardopts +1 -0
  6. data/CODE_OF_CONDUCT.md +22 -0
  7. data/Gemfile +16 -0
  8. data/Gemfile.lock +42 -0
  9. data/LICENSE.txt +20 -0
  10. data/README.md +112 -0
  11. data/VERSION +1 -0
  12. data/lib/ravelry.rb +39 -0
  13. data/lib/ravelry/author.rb +27 -0
  14. data/lib/ravelry/category.rb +57 -0
  15. data/lib/ravelry/configuration.rb +11 -0
  16. data/lib/ravelry/craft.rb +19 -0
  17. data/lib/ravelry/data.rb +25 -0
  18. data/lib/ravelry/pack.rb +135 -0
  19. data/lib/ravelry/pattern.rb +390 -0
  20. data/lib/ravelry/pattern_needle.rb +54 -0
  21. data/lib/ravelry/pattern_type.rb +34 -0
  22. data/lib/ravelry/photo.rb +69 -0
  23. data/lib/ravelry/printing.rb +70 -0
  24. data/lib/ravelry/utils/build.rb +128 -0
  25. data/lib/ravelry/utils/utilities.rb +14 -0
  26. data/lib/ravelry/version.rb +3 -0
  27. data/lib/ravelry/yarn.rb +39 -0
  28. data/lib/ravelry/yarn_weight.rb +48 -0
  29. data/ravelry.gemspec +27 -0
  30. data/spec/helpers/helpers.rb +106 -0
  31. data/spec/helpers/pack_helpers.rb +107 -0
  32. data/spec/helpers/pattern_helpers.rb +190 -0
  33. data/spec/helpers/yarn_helpers.rb +27 -0
  34. data/spec/helpers/yarn_weight_helpers.rb +25 -0
  35. data/spec/ravelry/author_spec.rb +33 -0
  36. data/spec/ravelry/category_spec.rb +46 -0
  37. data/spec/ravelry/craft_spec.rb +22 -0
  38. data/spec/ravelry/data_spec.rb +27 -0
  39. data/spec/ravelry/pack_spec.rb +114 -0
  40. data/spec/ravelry/pattern_needle_spec.rb +52 -0
  41. data/spec/ravelry/pattern_spec.rb +301 -0
  42. data/spec/ravelry/pattern_type_spec.rb +28 -0
  43. data/spec/ravelry/photo_spec.rb +56 -0
  44. data/spec/ravelry/printing_spec.rb +65 -0
  45. data/spec/ravelry/utils/build_spec.rb +187 -0
  46. data/spec/ravelry/yarn_spec.rb +30 -0
  47. data/spec/ravelry/yarn_weight_spec.rb +42 -0
  48. data/spec/ravelry_spec.rb +3 -0
  49. data/spec/spec_helper.rb +30 -0
  50. metadata +154 -0
@@ -0,0 +1,69 @@
1
+ module Ravelry
2
+
3
+ # The information used to create `Ravelry::Photo` currently comes from {Ravelry::Pattern} objects.
4
+ #
5
+ # See {Ravelry::Pattern} for more information about `Pattern` objects.
6
+ #
7
+ # To utilize the `get`, `post`, `delete`, `get_sizes` methods, you have to be authenticated.
8
+ #
9
+ class Photo < Data
10
+
11
+ def build; end
12
+
13
+ def get
14
+ # TODO - requires authentication
15
+ end
16
+
17
+ def post
18
+ # TODO - requires authentication
19
+ end
20
+
21
+ def delete
22
+ # TODO - requires authentication
23
+ end
24
+
25
+ def get_sizes
26
+ # TODO - requires authentication
27
+ end
28
+
29
+ def flickr_url
30
+ data[:flickr_url]
31
+ end
32
+
33
+ def small_url
34
+ data[:small_url]
35
+ end
36
+
37
+ def medium_url
38
+ data[:medium_url]
39
+ end
40
+
41
+ def square_url
42
+ data[:square_url]
43
+ end
44
+
45
+ def thumbnail_url
46
+ data[:thumbnail_url]
47
+ end
48
+
49
+ def shelved_url
50
+ data[:shelved_url]
51
+ end
52
+
53
+ def sort_order
54
+ data[:sort_order]
55
+ end
56
+
57
+ # Offsets are used to place a small image in a 170x170 pixel square frame.
58
+ #
59
+ def x_offset
60
+ data[:x_offset]
61
+ end
62
+
63
+ # Offsets are used to place a small image in a 170x170 pixel square frame.
64
+ #
65
+ def y_offset
66
+ data[:y_offset]
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,70 @@
1
+ module Ravelry
2
+
3
+ # The information used to create `Ravelry::Printing` objects comes from {Ravelry::Pattern} objects.
4
+ #
5
+ # You should not create `Printing` objects manually; they are all created–and owned–by a {Ravelry::Pattern}.
6
+ #
7
+ # See {Ravelry::Pattern} for more information about `Pattern` objects.
8
+ #
9
+ class Printing
10
+
11
+ attr_reader :price, :permalink, :name, :author, :url, :amazon_rating, :pattern_count, :amazon_url, :shelf_image_path, :list_price
12
+
13
+ def initialize(printing)
14
+ @printing = printing
15
+ @pattern_source = printing[:pattern_source]
16
+
17
+ # Price of the printing source.
18
+ #
19
+ @price = @pattern_source[:price]
20
+
21
+ # Permalink for printing.
22
+ #
23
+ @permalink = @pattern_source[:permalink]
24
+
25
+ # Name of the printing.
26
+ #
27
+ @name = @pattern_source[:name]
28
+
29
+ # Author of the printed source (if any).
30
+ #
31
+ @author = @pattern_source[:author]
32
+
33
+ # URL of the printing.
34
+ #
35
+ @url = @pattern_source[:url]
36
+
37
+ # Printing's rating on Amazon.
38
+ #
39
+ @amazon_rating = @pattern_source[:amazon_rating]
40
+
41
+ # Number of patterns available in this printing.
42
+ #
43
+ @pattern_count = @pattern_source[:pattern_count]
44
+
45
+ # Printing's Amazon URL.
46
+ #
47
+ @amazon_url = @pattern_source[:amazon_url]
48
+
49
+ # Path to image, if any.
50
+ #
51
+ @shelf_image_path = @pattern_source[:shelf_image_path]
52
+
53
+ # List price of the printing.
54
+ #
55
+ @list_price = @pattern_source[:list_price]
56
+ end
57
+
58
+ # Boolean value. Is this resource out of print?
59
+ #
60
+ def out_of_print?
61
+ @pattern_source[:out_of_print]
62
+ end
63
+
64
+ # Boolean value. Is this the primary source of the pattern?
65
+ #
66
+ def primary_source?
67
+ @printing[:primary_source]
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,128 @@
1
+ module Ravelry
2
+
3
+ # Utility module that takes the JSON response from the API call and creates the appropriate objects.
4
+ #
5
+ module Build
6
+
7
+ # Creates and returns a {Ravelry::Author} object.
8
+ #
9
+ # See {Ravelry::Author} for more information.
10
+ #
11
+ def self.author(data)
12
+ @author = Author.new(data[:pattern_author])
13
+ end
14
+
15
+ # Creates and returns an array of {Ravelry::Category} objects.
16
+ #
17
+ # See {Ravelry::Category} for more information.
18
+ #
19
+ def self.categories(data)
20
+ @categories = []
21
+ data[:pattern_categories].each do |cat|
22
+ @categories << Category.new(cat)
23
+ end
24
+ @categories
25
+ end
26
+
27
+ # Creates and returns a {Ravelry::Craft} object.
28
+ #
29
+ # See {Ravelry::Craft} for more information.
30
+ #
31
+ def self.craft(data)
32
+ @craft = Craft.new(data[:craft])
33
+ end
34
+
35
+ # Creates and returns an array of {Ravelry::PatternNeedle} objects.
36
+ #
37
+ # There is more than one API endpoint for Needles. This may not be the one you are looking for.
38
+ #
39
+ # See {Ravelry::PatternNeedle} for more information.
40
+ #
41
+ def self.needles(data)
42
+ @needles = []
43
+ data[:pattern_needle_sizes].each do |ndl|
44
+ @needles << PatternNeedle.new(ndl)
45
+ end
46
+ @needles
47
+ end
48
+
49
+ # Creates and returns an array of {Ravelry::Pack} objects.
50
+ #
51
+ # See {Ravelry::Pack} for more information.
52
+ #
53
+ def self.packs(data)
54
+ @packs = []
55
+ data[:packs].each do |pack_data|
56
+ pack = Pack.new
57
+ pack.data = pack_data
58
+ @packs << pack
59
+ end
60
+ @packs
61
+ end
62
+
63
+ # Creates and returns a of {Ravelry::PatternType} object.
64
+ #
65
+ # This is not the same as a PatternCategory object.
66
+ #
67
+ # See {Ravelry::PatternType} for more information.
68
+ #
69
+ def self.pattern_type(data)
70
+ @pattern_type = PatternType.new(data[:pattern_type])
71
+ end
72
+
73
+ # Creates and returns an array of {Ravelry::Photo} objects.
74
+ #
75
+ # See {Ravelry::Photo} for more information.
76
+ #
77
+ def self.photos(data)
78
+ @photos = []
79
+ data[:photos].each do |photo_data|
80
+ photo = Photo.new(photo_data[:id])
81
+ photo.data = photo_data
82
+ @photos << photo
83
+ end
84
+ @photos
85
+ end
86
+
87
+ # Creates and returns an array of {Ravelry::Printing} objects.
88
+ #
89
+ # See {Ravelry::Printing} for more information.
90
+ #
91
+ def self.printings(data)
92
+ @printings = []
93
+ data[:printings].each do |printing_data|
94
+ @printings << Printing.new(printing_data)
95
+ end
96
+ @printings
97
+ end
98
+
99
+ # Creates and returns an array of {Ravelry::Yarn} objects.
100
+ #
101
+ # See {Ravelry::Yarn} for more information.
102
+ #
103
+ def self.yarns(data)
104
+ @yarns = []
105
+ data[:packs].each do |pack_data|
106
+ yarn = Yarn.new
107
+ yarn.data = pack_data[:yarn]
108
+ @yarns << yarn
109
+ end
110
+ @yarns
111
+ end
112
+
113
+ # Creates and returns an array of {Ravelry::YarnWeight} objects.
114
+ #
115
+ # See {Ravelry::YarnWeight} for more information.
116
+ #
117
+ def self.yarn_weights(data)
118
+ @yarn_weights = []
119
+ data[:packs].each do |pack|
120
+ yarn_weight = YarnWeight.new
121
+ yarn_weight.data = pack[:yarn_weight]
122
+ @yarn_weights << yarn_weight
123
+ end
124
+ @yarn_weights
125
+ end
126
+
127
+ end
128
+ end
@@ -0,0 +1,14 @@
1
+ module Ravelry
2
+
3
+ # Utility module that handles date, string, and number parsing.
4
+ #
5
+ module Utilities
6
+
7
+ # Expects a format readable by Ruby's Date library.
8
+ #
9
+ def self.pretty_full_date(string)
10
+ parsed = Date.parse(string)
11
+ parsed.strftime("%B %e, %Y")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Ravelry
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,39 @@
1
+ module Ravelry
2
+
3
+ # The information used to create `Ravelry::Yarn` currently comes from {Ravelry::Pattern} objects.
4
+ #
5
+ # See {Ravelry::Pattern} for more information about `Pattern` objects.
6
+ #
7
+ # This class will be updated in future to perform GET, POST, PUT, and DESTROY requests.
8
+ #
9
+ class Yarn < Data
10
+
11
+ def build; end
12
+
13
+ # Gets yarn permalink from existing `data`.
14
+ def permalink
15
+ data[:permalink]
16
+ end
17
+
18
+ # Gets yarn company from existing `data`.
19
+ def company
20
+ data[:yarn_company_name]
21
+ end
22
+
23
+ # Gets yarn name from existing `data`.
24
+ def name
25
+ data[:name]
26
+ end
27
+
28
+ # Gets yarn company_id from existing `data`.
29
+ def company_id
30
+ data[:yarn_company_id]
31
+ end
32
+
33
+ # Handles API call and parses JSON response.
34
+ def fetch_and_parse
35
+ # TODO
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,48 @@
1
+ module Ravelry
2
+
3
+ # The information used to create `Ravelry::YarnWeight` currently comes from {Ravelry::Pattern} objects.
4
+ #
5
+ # See {Ravelry::Pattern} for more information about `Pattern` objects.
6
+ #
7
+ # This class will be updated in future to perform GET, POST, PUT, and DESTROY requests.
8
+ #
9
+ class YarnWeight < Data
10
+
11
+ def build; end
12
+
13
+ # Gets yarn weight's name from existing `data`.
14
+ def name
15
+ data[:name]
16
+ end
17
+
18
+ # Gets yarn weight's min_gauge from existing `data`.
19
+ def min_gauge
20
+ data[:min_gauge]
21
+ end
22
+
23
+ # Gets yarn weight's wpi from existing `data`.
24
+ def wpi
25
+ data[:wpi]
26
+ end
27
+
28
+ # Gets yarn weight's crochet_gauge from existing `data`.
29
+ def crochet_gauge
30
+ data[:crochet_gauge]
31
+ end
32
+
33
+ # Gets yarn weight's ply from existing `data`.
34
+ def ply
35
+ data[:ply]
36
+ end
37
+
38
+ # Gets yarn weight's knit_gauge from existing `data`.
39
+ def knit_gauge
40
+ data[:knit_gauge]
41
+ end
42
+
43
+ # Gets yarn weight's max_gauge from existing `data`.
44
+ def max_gauge
45
+ data[:max_gauge]
46
+ end
47
+ end
48
+ end
data/ravelry.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ravelry/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ravelry"
8
+ spec.version = Ravelry::VERSION
9
+ spec.authors = ["Liz Abinante"]
10
+ spec.date = "2013-12-22"
11
+ spec.summary = "Ruby gem for accessing the Ravelry API."
12
+ spec.description = "Ruby gem for accessing the Ravelry API painlessly, easily, and awesomely."
13
+ spec.email = "me@liz.codes"
14
+ spec.homepage = "http://github.com/ArtCraftCode/ravelry"
15
+ spec.licenses = ["MIT"]
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_dependency "typhoeus", "~> 0.6"
26
+ end
27
+
@@ -0,0 +1,106 @@
1
+ module Helpers
2
+ # Generic test helpers
3
+
4
+ def pattern_author
5
+ {
6
+ :permalink=>"liz-abinante", :name=>"Liz Abinante", :id=>19297,
7
+ :favorites_count=>1314, :patterns_count=>48
8
+ }
9
+ end
10
+
11
+ def yarn_hash
12
+ {
13
+ :permalink=>"miss-babs-yummy-superwash-sport---3-ply",
14
+ :yarn_company_name=>"Miss Babs",
15
+ :yarn_company_id=>1119,
16
+ :name=>"Yummy Superwash Sport - 3 Ply",
17
+ :id=>18714
18
+ }
19
+ end
20
+
21
+ def yarn_weight_hash
22
+ {
23
+ :name=>"Sport",
24
+ :min_gauge=>nil,
25
+ :wpi=>"12",
26
+ :id=>10,
27
+ :crochet_gauge=>nil,
28
+ :ply=>"5",
29
+ :knit_gauge=>"24-26",
30
+ :max_gauge=>nil
31
+ }
32
+ end
33
+
34
+ def categories
35
+ {
36
+ :permalink=>"shawl-wrap", :name=>"Shawl / Wrap", :id=>350,
37
+ :parent=>
38
+ {
39
+ :permalink=>"neck-torso", :name=>"Neck / Torso", :id=>338,
40
+ :parent=>
41
+ {
42
+ :permalink=>"accessories", :name=>"Accessories", :id=>337,
43
+ :parent=>
44
+ {
45
+ :permalink=>"categories", :name=>"Categories", :id=>301
46
+ }
47
+ }
48
+ }
49
+ }
50
+ end
51
+
52
+ def craft
53
+ { :permalink=>"knitting", :name=>"Knitting", :id=>2 }
54
+ end
55
+
56
+ def needle
57
+ { :hook=>"E", :us_steel=>"00", :name=>"US 4 - 3.5 mm",
58
+ :crochet=>false, :metric=>3.5, :knitting=>true, :us=>"4 ",
59
+ :id=>4 }
60
+ end
61
+
62
+ def pattern_type
63
+ {
64
+ :permalink=>"shawl", :name=>"Shawl/Wrap", :clothing=>true,
65
+ :id=>10
66
+ }
67
+ end
68
+
69
+ def photo
70
+ { :flickr_url=>nil,
71
+ :small_url=>"http://images4.ravelrycache.com/uploads/feministy/197032385/_D7C0070-Edit-Edit_small_best_fit.JPG",
72
+ :x_offset=>-82,
73
+ :shelved_url=>"http://images4.ravelrycache.com/uploads/feministy/197032385/_D7C0070-Edit-Edit_shelved.JPG",
74
+ :y_offset=>0,
75
+ :sort_order=>1,
76
+ :id=>35912328,
77
+ :square_url=>"http://images4-b.ravelrycache.com/uploads/feministy/197032385/_D7C0070-Edit-Edit_square.JPG",
78
+ :medium_url=>"http://images4.ravelrycache.com/uploads/feministy/197032385/_D7C0070-Edit-Edit_medium.JPG",
79
+ :thumbnail_url=>"h"
80
+ }
81
+ end
82
+
83
+ def printing
84
+ [
85
+ {:pattern_source=>
86
+ {
87
+ :price=>nil, :permalink=>"liz-abinantes-ravelry-store",
88
+ :out_of_print=>false, :name=>"Liz Abinante's Ravelry Store",
89
+ :author=>nil, :url=>"http://www.ravelry.com/stores/feministy",
90
+ :amazon_rating=>nil, :pattern_count=>3, :amazon_url=>nil,
91
+ :shelf_image_path=>nil, :list_price=>nil
92
+ },
93
+ :primary_source=>true
94
+ },
95
+ {:pattern_source=>
96
+ {
97
+ :price=>nil, :permalink=>"feministy", :out_of_print=>false,
98
+ :name=>"Feministy.com", :author=>"", :url=>"http://feministy.com/",
99
+ :amazon_rating=>nil, :pattern_count=>47, :amazon_url=>nil,
100
+ :shelf_image_path=>nil, :list_price=>nil
101
+ },
102
+ :primary_source=>false
103
+ }
104
+ ]
105
+ end
106
+ end