ravelry 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0726ba5d5561d16af2180b2cfaf25a7fe90c1773
4
+ data.tar.gz: 6fec858f6080353788ad179e54270d4af4580783
5
+ SHA512:
6
+ metadata.gz: 88901547a84900f2705574fa54adec93dea93fbeb9521d5f4aa32004fc610ae44f9ea164d9714c2dc669eda9f5d80ed44027a70e6ef7c37e35fd5b8356e4efe5
7
+ data.tar.gz: a399b5db5924138a4bf0c7c9a0a1af36d7379aae57a9ae4c10a15f9dd874745f56a8a454e662414febdb8df8bc7819e4642403738fdf22f86cbd746e28581cdc
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # yard generated
2
+ doc
3
+ .yardoc
4
+
5
+ # bundler
6
+ .bundle
7
+
8
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.2
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
@@ -0,0 +1,22 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6
+
7
+ Examples of unacceptable behavior by participants include:
8
+
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17
+
18
+ This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21
+
22
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "typhoeus", "~> 0.6"
4
+
5
+ group :development do
6
+ gem "rspec", "~> 2.14.1"
7
+ gem "bundler"
8
+ gem "yard"
9
+ gem "redcarpet"
10
+ end
11
+
12
+ group :test do
13
+ gem "rake"
14
+ gem "pry"
15
+ gem "pry-nav"
16
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ coderay (1.1.0)
5
+ diff-lcs (1.2.5)
6
+ ethon (0.7.1)
7
+ ffi (>= 1.3.0)
8
+ ffi (1.9.6)
9
+ method_source (0.8.2)
10
+ pry (0.10.3)
11
+ coderay (~> 1.1.0)
12
+ method_source (~> 0.8.1)
13
+ slop (~> 3.4)
14
+ pry-nav (0.2.4)
15
+ pry (>= 0.9.10, < 0.11.0)
16
+ rake (10.1.1)
17
+ redcarpet (3.0.0)
18
+ rspec (2.14.1)
19
+ rspec-core (~> 2.14.0)
20
+ rspec-expectations (~> 2.14.0)
21
+ rspec-mocks (~> 2.14.0)
22
+ rspec-core (2.14.7)
23
+ rspec-expectations (2.14.4)
24
+ diff-lcs (>= 1.1.3, < 2.0)
25
+ rspec-mocks (2.14.4)
26
+ slop (3.6.0)
27
+ typhoeus (0.6.9)
28
+ ethon (>= 0.7.1)
29
+ yard (0.8.7.3)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler
36
+ pry
37
+ pry-nav
38
+ rake
39
+ redcarpet
40
+ rspec (~> 2.14.1)
41
+ typhoeus (~> 0.6)
42
+ yard
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Liz Abinante
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # Ravelry
2
+
3
+ _You are reading documentation for version: 0.0.1_
4
+
5
+ [ ![Codeship Status for ArtCraftCode/ravelry](https://codeship.com/projects/fc6710e0-5719-0133-36cc-5ebc52a48109/status?branch=0.0.1)](https://codeship.com/projects/109462)
6
+
7
+ This gem is actively being developed. Be sure to check the branch for the version you're using as breaking changes can (and will!) be introduced.
8
+
9
+ To see what I am working on next, visit the project's [Trello board](https://trello.com/b/o8gs4cWI/ravelry).
10
+
11
+ The Ruby gem for accessing the Ravelry API painlessly, easily, and awesomely.
12
+
13
+ Ravelry API documentation is currently available [here](http://www.ravelry.com/api).
14
+
15
+ ## API coverage
16
+
17
+ * `Patterns#show` (`GET`)
18
+
19
+ # Installation
20
+
21
+ Welcome to a magical land where gems rule the world. To install, type:
22
+
23
+ ```
24
+ gem install ravelry
25
+ ```
26
+
27
+ Hooray! You now have a gem.
28
+
29
+ Add to your `Gemfile`:
30
+
31
+ ```
32
+ gem "ravelry", "~> 0.0.1"
33
+ ```
34
+
35
+ **I highly recommend pinning your version** because the gem is in active development and I _promise_ I will break shit.
36
+
37
+ Run `bundle install` and proceed as usual.
38
+
39
+ ## API keys
40
+
41
+ API keys must be configured in the gem setup. You can do this anywhere in your application before you make API calls using the gem.
42
+
43
+ ```ruby
44
+ Ravelry.configure do |config|
45
+ config.access_key = ''
46
+ config.secret_key = ''
47
+ config.personal_key = ''
48
+ end
49
+ ```
50
+
51
+ * `config.access_key` - your Ravelry access key
52
+ * `config.secret_key` - your Ravelry secret key
53
+ * `config.personal_key` - wait for it! Your Ravelry personal key; primarily used for OAuth (not yet implemented in the gem)
54
+
55
+ Getting these keys requires a (free) Ravelry account and that you agree to the terms of use for the API.
56
+
57
+ # Usage
58
+
59
+ Full documentation for this gem is available [here](http://www.rubydoc.info/gems/ravelry/0.0.1).
60
+
61
+ # API quirks
62
+
63
+ ## Accessing pattern ids (for `Ravelry::Patterns`)
64
+
65
+ To use the `Patterns#show` endpoint, you need the pattern id from Ravelry. You can use the pattern search API to search for the pattern name and get this information, but that is not yet implemented in the gem.
66
+
67
+ In the meantime, navigate to a pattern page in Ravelry and open up the JavaScript console. Type this in:
68
+
69
+ ```javascript
70
+ $$('.difficulty').first().id
71
+ ```
72
+
73
+ You should see something like this: ```"pattern_419443_difficulty_score"```.
74
+
75
+ ```419443``` is your pattern id.
76
+
77
+ # Conventions
78
+
79
+ This gem makes use of several conventions that are worth noting on a global scale.
80
+
81
+ ## Method names ending with `_count` return integers.
82
+
83
+ Example:
84
+
85
+ ```ruby
86
+ pattern.comments_count
87
+ # => 4
88
+ ```
89
+
90
+ ## Method names ending with `_float`, `_integer`, etc return that object type.
91
+
92
+ Float to Integer conversions are done using round(0).
93
+
94
+ Example:
95
+
96
+ ```ruby
97
+ pattern.difficulty_average_float
98
+ # => 4.666666667
99
+
100
+ pattern.difficulty_average_integer
101
+ # => 5
102
+ ```
103
+
104
+ # Contributing
105
+
106
+ Hey! You want to contribute? That is super, super awesome. Visit the project's [Trello board](https://trello.com/b/o8gs4cWI/ravelry) to see what's coming up next or what is already in progress.
107
+
108
+ Send me a pull request! Note that your pull request will not be accepted if you don't write tests **and documentation** for your code (the test part kind of goes without saying, but I wanted to make sure that you knew about it and the documentation).
109
+
110
+ To run specs locally, simply `bundle` and then run `rpsec`.
111
+
112
+ Documentation is generated by YARD and is producted using inline comments. Comments use Markdown syntax. You can run `yard server` to get a live server of documentation while you're working :)
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/ravelry.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'json'
2
+ require 'typhoeus'
3
+
4
+ require 'ravelry/configuration'
5
+
6
+ require 'ravelry/utils/build'
7
+ require 'ravelry/utils/utilities'
8
+
9
+ require 'ravelry/author'
10
+ require 'ravelry/category'
11
+ require 'ravelry/craft'
12
+ require 'ravelry/data'
13
+ require 'ravelry/pack'
14
+ require 'ravelry/pattern'
15
+ require 'ravelry/pattern_needle'
16
+ require 'ravelry/pattern_type'
17
+ require 'ravelry/photo'
18
+ require 'ravelry/printing'
19
+ require 'ravelry/yarn'
20
+ require 'ravelry/yarn_weight'
21
+
22
+ # Parent grouping for all classes.
23
+ module Ravelry
24
+ class << self
25
+ attr_accessor :configuration
26
+ end
27
+
28
+ def self.configuration
29
+ @configuration ||= Configuration.new
30
+ end
31
+
32
+ def self.reset
33
+ @configuration = Configuration.new
34
+ end
35
+
36
+ def self.configure
37
+ yield(configuration)
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ module Ravelry
2
+
3
+ # There is no API access point for PatternAuthors. The information used to create `Ravelry::Author` comes from {Ravelry::Pattern} objects.
4
+ #
5
+ # You should not create `Author` objects manually; they are all created–and owned by–by a {Ravelry::Pattern}.
6
+ #
7
+ # See {Ravelry::Pattern} for more information about `Pattern` objects.
8
+ #
9
+ # This does not inherit from {Ravelry::Data} because it doesn't have a corresponding API endpoint.
10
+ #
11
+ class Author
12
+ attr_reader :id, :name, :permalink, :patterns_count, :favorites_count
13
+
14
+ # Creates new `Author` from Ravelry API PatternAuthor attributes.
15
+ #
16
+ # All class variables are readonly.
17
+ #
18
+ def initialize(pattern_author)
19
+ @id = pattern_author[:id]
20
+ @name = pattern_author[:name]
21
+ @permalink = pattern_author[:permalink]
22
+ @patterns_count = pattern_author[:patterns_count]
23
+ @favorites_count = pattern_author[:favorites_count]
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,57 @@
1
+ module Ravelry
2
+
3
+ # There is no API access point for PatternCategories. The information used to create `Ravelry::Category` comes from {Ravelry::Pattern} objects.
4
+ #
5
+ # You should not create `Category` objects manually; they are all created–and owned by–by a {Ravelry::Pattern}.
6
+ #
7
+ # See {Ravelry::Pattern} for more information about `Pattern` objects.
8
+ #
9
+ # This does not inherit from {Ravelry::Data} because it doesn't have a corresponding API endpoint.
10
+ #
11
+ class Category
12
+ attr_reader :name, :permalink, :parent_name, :parent_permalink, :grandparent_name, :grandparent_permalink, :greatgrandparent_name, :greatgrandparent_permalink
13
+
14
+ # Creates new `Category` from Ravelry API PatternCategories attributes up to the great grandparent level
15
+ #
16
+ # All class variables are readonly.
17
+ #
18
+ def initialize(category)
19
+ @name = category[:name]
20
+ @permalink = category[:permalink]
21
+ @category = category
22
+ set_relatives
23
+ end
24
+
25
+ protected
26
+ # Returns parent name and sets parent attributes from existing `data`.
27
+ def parent
28
+ if @category[:parent]
29
+ @parent_permalink = @category[:parent][:permalink]
30
+ @parent_name = @category[:parent][:name]
31
+ end
32
+ end
33
+
34
+ # Returns parent name and sets grandparent attributes from existing `data`.
35
+ def grandparent
36
+ if @category[:parent][:parent]
37
+ @grandparent_permalink = @category[:parent][:parent][:permalink]
38
+ @grandparent_name = @category[:parent][:parent][:name]
39
+ end
40
+ end
41
+
42
+ # Returns parent name and sets greatgrandparent attributes from existing `data`.
43
+ def greatgrandparent
44
+ if @category[:parent][:parent][:parent]
45
+ @greatgrandparent_permalink = @category[:parent][:parent][:parent][:permalink]
46
+ @greatgrandparent_name = @category[:parent][:parent][:parent][:name]
47
+ end
48
+ end
49
+
50
+ private
51
+ def set_relatives
52
+ parent if @category[:parent]
53
+ grandparent if @category[:parent][:parent]
54
+ greatgrandparent if @category[:parent][:parent][:parent]
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,11 @@
1
+ module Ravelry
2
+ class Configuration
3
+ attr_accessor :access_key, :secret_key, :personal_key
4
+
5
+ def initialize
6
+ @access_key = nil
7
+ @secret_key = nil
8
+ @personal_key = nil
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ module Ravelry
2
+
3
+ # The information used to create `Ravelry::Craft` currently comes from {Ravelry::Pattern} objects.
4
+ #
5
+ # You should not create `Craft` 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 Craft
10
+
11
+ attr_reader :permalink, :name
12
+
13
+ def initialize(data)
14
+ @permalink = data[:permalink]
15
+ @name = data[:name]
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,25 @@
1
+ module Ravelry
2
+
3
+ # Parent class that controls initialization and fetching for API objects.
4
+ class Data
5
+ attr_accessor :id
6
+ attr_reader :data
7
+
8
+ def initialize(id=nil)
9
+ @id = id
10
+ end
11
+
12
+ def data=(d)
13
+ @data = d
14
+ build
15
+ self
16
+ end
17
+
18
+ private
19
+ # Determines if a GET request needs to be made.
20
+ def get?
21
+ @id && !@data
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,135 @@
1
+ module Ravelry
2
+
3
+ # The information used to create `Ravelry::Pack` 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 Pack < Data
10
+
11
+ def build; end
12
+
13
+ # Gets quantity_description from existing `data`.
14
+ def quantity_description
15
+ data[:quantity_description]
16
+ end
17
+
18
+ # Gets yarn_id from existing `data`.
19
+ def yarn_id
20
+ data[:yarn_id]
21
+ end
22
+
23
+ # Gets total_grams from existing `data`.
24
+ def total_grams
25
+ data[:total_grams]
26
+ end
27
+
28
+ # Gets project_id from existing `data`.
29
+ def project_id
30
+ data[:project_id]
31
+ end
32
+
33
+ # Gets shop_id from existing `data`.
34
+ def shop_id
35
+ data[:shop_id]
36
+ end
37
+
38
+ # Gets prefer_metric_weight from existing `data`.
39
+ def prefer_metric_weight
40
+ data[:prefer_metric_weight]
41
+ end
42
+
43
+ # Gets prefer_metric_length from existing `data`.
44
+ def prefer_metric_length
45
+ data[:prefer_metric_length]
46
+ end
47
+
48
+ # Gets ounces_per_skein from existing `data`.
49
+ def ounces_per_skein
50
+ data[:ounces_per_skein]
51
+ end
52
+
53
+ # Gets dye_lot from existing `data`.
54
+ def dye_lot
55
+ data[:dye_lot]
56
+ end
57
+
58
+ # Gets skeins from existing `data`.
59
+ def skeins
60
+ data[:skeins]
61
+ end
62
+
63
+ # Gets id from existing `data`.
64
+ def id
65
+ data[:id]
66
+ end
67
+
68
+ # Gets grams_per_skein from existing `data`.
69
+ def grams_per_skein
70
+ data[:grams_per_skein]
71
+ end
72
+
73
+ # Gets color_family_id from existing `data`.
74
+ def color_family_id
75
+ data[:color_family_id]
76
+ end
77
+
78
+ # Gets shop_name from existing `data`.
79
+ def shop_name
80
+ data[:shop_name]
81
+ end
82
+
83
+ # Gets total_meters from existing `data`.
84
+ def total_meters
85
+ data[:total_meters]
86
+ end
87
+
88
+ # Gets stash_id from existing `data`.
89
+ def stash_id
90
+ data[:stash_id]
91
+ end
92
+
93
+ # Gets total_ounces from existing `data`.
94
+ def total_ounces
95
+ data[:total_ounces]
96
+ end
97
+
98
+ # Gets primary_pack_id from existing `data`.
99
+ def primary_pack_id
100
+ data[:primary_pack_id]
101
+ end
102
+
103
+ # Gets personal_name from existing `data`.
104
+ def personal_name
105
+ data[:personal_name]
106
+ end
107
+
108
+ # Gets colorway from existing `data`.
109
+ def colorway
110
+ data[:colorway]
111
+ end
112
+
113
+ # Gets meters_per_skein from existing `data`.
114
+ def meters_per_skein
115
+ data[:meters_per_skein]
116
+ end
117
+
118
+ # Gets yarn_name from existing `data`.
119
+ def yarn_name
120
+ data[:yarn_name]
121
+ end
122
+
123
+ # Gets yards_per_skein from existing `data`.
124
+ def yards_per_skein
125
+ data[:yards_per_skein]
126
+ end
127
+
128
+ # Gets total_yards from existing `data`.
129
+ def total_yards
130
+ data[:total_yards]
131
+ end
132
+
133
+ end
134
+
135
+ end