ravelry 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9132400df864b998861fc08da936fdafd7da5dc
4
- data.tar.gz: ce313f70e9acb79289e801f5872e761d7a2a19af
3
+ metadata.gz: b59dc93738ed456de23da333441d63e0cc44bd8b
4
+ data.tar.gz: 78679aaf9e8a39d0a4041651d1e8e4403a089eab
5
5
  SHA512:
6
- metadata.gz: 1adcd5d8930d86cfa2a948995fcf54b1251d8358b16d9c6783832e60c333ddfaf5197b7857256d899d69a9676cf261523eaf2b199c58cee4eb8b76c2e0346944
7
- data.tar.gz: 0697d617a95f2f02f31a4a0b2598ebbe7caca22bbbf2fd51be5b6e4603483dc6c8a499de4d6a0caad8aca308a3a12b995634ef9d6925f1fc5724c05833e1b4f1
6
+ metadata.gz: e8b47e7535e1a7803f312286c32354ceabb614be9691eea5b690065e86d8d584b5f9c45cc9dc14aa2a688bb4e8e5fe31c54129c590799013a9e2032a2f66d3b6
7
+ data.tar.gz: b7a05c4f35c94f9b517258a6eda0c0eadeb07b0bd1e4c8cf08ac1ad1d7fe5030fe5c9c2479c6b8edeae3c4f13ee96ffda735e506705cd27c312e2608007a76b2
data/README.md CHANGED
@@ -1,35 +1,38 @@
1
1
  # Ravelry
2
2
 
3
- _You are reading documentation for version: 0.0.7_
3
+ _You are reading documentation for version: 0.0.8_
4
4
 
5
- [ ![Codeship Status for ArtCraftCode/ravelry](https://codeship.com/projects/fc6710e0-5719-0133-36cc-5ebc52a48109/status?branch=0.0.7)](https://codeship.com/projects/109462)
5
+ [ ![Codeship Status for ArtCraftCode/ravelry](https://codeship.com/projects/fc6710e0-5719-0133-36cc-5ebc52a48109/status?branch=0.0.8)](https://codeship.com/projects/109462)
6
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.
7
+ The Ruby gem for accessing the Ravelry API painlessly, easily, and awesomely! This gem is actively being developed. **Be sure to check the branch for the version you're using.**
8
8
 
9
- To see what I am working on next, visit the project's [Trello board](https://trello.com/b/o8gs4cWI/ravelry).
9
+ **Important and helpful links:**
10
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).
11
+ - [Full gem documentation (version 0.0.8)](http://www.rubydoc.info/gems/ravelry/0.0.8)
12
+ - [Changelog](https://github.com/ArtCraftCode/ravelry/blob/0.0.8/CHANGELOG.md)
13
+ - [Project Trello board](https://trello.com/b/o8gs4cWI/ravelry)
14
+ - [Ravelry API documentation](http://www.ravelry.com/api)
14
15
 
15
16
  ## API coverage
16
17
 
17
- See documentation for each class (or module) to see how to initialize the objects.
18
+ See [documentation](http://www.rubydoc.info/gems/ravelry/0.0.8) for each class (or module) to see how to initialize the objects.
18
19
 
19
20
  API | Endpoint | Ravelry gem class / module
20
21
  ----|----------|------------------
21
22
  **Misc** | [color_families](http://www.ravelry.com/api#/_color_families) | `Ravelry::Misc.color_families`
22
23
  **Misc** | [yarn_weights](http://www.ravelry.com/api#/_yarn_weights) | `Ravelry::Misc.yarn_weights`
24
+ **Misc** | [current_user](http://www.ravelry.com/api#/_current_user) | `Ravelry::Misc.current_user`
23
25
  **Needles** | [list](http://www.ravelry.com/api#needles_list) | `Ravelry::Needles.list`
24
26
  **Needles** | [sizes](http://www.ravelry.com/api#needles_sizes) | `Ravelry::Needles.sizes`
25
27
  **Needles** | [types](http://www.ravelry.com/api#needles_types) | `Ravelry::Needles.types`
28
+ **Patterns** | [comments](http://www.ravelry.com/api#patterns_comments) | `Ravelry::Pattern.comments`
26
29
  **Patterns** | [search](http://www.ravelry.com/api#patterns_search) | `Ravelry::Pattern.search`
27
30
  **Patterns** | [show](http://www.ravelry.com/api#patterns_show) | `Ravelry::Pattern.get`
28
31
  **People** | [show](http://www.ravelry.com/api#people_show) | `Ravelry::User.get`
29
32
 
30
33
  # Installation
31
34
 
32
- Welcome to a magical land where gems rule the world. To install, type:
35
+ To install, type:
33
36
 
34
37
  ```
35
38
  gem install ravelry
@@ -40,16 +43,16 @@ Hooray! You now have a gem.
40
43
  Add to your `Gemfile`:
41
44
 
42
45
  ```ruby
43
- gem "ravelry", "~> 0.0.7"
46
+ gem "ravelry", "~> 0.0.8"
44
47
  ```
45
48
 
46
- **I highly recommend pinning your version** because the gem is in active development and I _promise_ I will break shit.
49
+ **I highly recommend pinning your version** because the gem is in active development and small changes and additions will be made regularly.
47
50
 
48
51
  Run `bundle install` and proceed as usual.
49
52
 
50
- ## API keys
53
+ # Configuration
51
54
 
52
- 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.
55
+ 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.
53
56
 
54
57
  ```ruby
55
58
  Ravelry.configure do |config|
@@ -75,23 +78,7 @@ Ravelry.configuration.personal_key
75
78
 
76
79
  # Usage
77
80
 
78
- Full documentation for this gem is available [here](http://www.rubydoc.info/gems/ravelry/0.0.7).
79
-
80
- # API quirks
81
-
82
- ## Accessing pattern ids (for `Ravelry::Patterns`)
83
-
84
- 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.
85
-
86
- In the meantime, navigate to a pattern page in Ravelry and open up the JavaScript console. Type this in:
87
-
88
- ```javascript
89
- $$('.difficulty').first().id
90
- ```
91
-
92
- You should see something like this: ```"pattern_419443_difficulty_score"```.
93
-
94
- ```419443``` is your pattern id.
81
+ Full documentation for this gem is available [here](http://www.rubydoc.info/gems/ravelry/0.0.8).
95
82
 
96
83
  # Conventions
97
84
 
@@ -124,7 +111,7 @@ pattern.difficulty_average_integer
124
111
 
125
112
  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.
126
113
 
127
- 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).
114
+ Send me a pull request! Please write tests, **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), and update the changelog with your additions under the next unreleased version.
128
115
 
129
116
  To run specs locally, simply `bundle` and then run `rpsec`.
130
117
 
@@ -10,6 +10,7 @@ require 'ravelry/utils/utilities'
10
10
  require 'ravelry/author'
11
11
  require 'ravelry/category'
12
12
  require 'ravelry/color_family'
13
+ require 'ravelry/comment'
13
14
  require 'ravelry/craft'
14
15
  require 'ravelry/data'
15
16
  require 'ravelry/misc'
@@ -0,0 +1,34 @@
1
+ module Ravelry
2
+
3
+ # The information used to create `Ravelry::Comment` comes from {Ravelry::Pattern} objects.
4
+ #
5
+ # You should not create `Comment` 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
+ class Comment
10
+ attr_reader :highlighted_project, :user, :html, :id
11
+
12
+ # Creates new `Comment` from Ravelry API Pattern Comment attributes.
13
+ #
14
+ # All class variables are readonly.
15
+ #
16
+ def initialize(data)
17
+ @data = data
18
+ @user = Ravelry::User.new
19
+ @user.data = data[:user]
20
+ @highlighted_project = data[:highlighted_project]
21
+ @html = data[:html]
22
+ @id = data[:id]
23
+ end
24
+
25
+ def replies
26
+ @reply_list ||= []
27
+ return @reply_list if @reply_list.any?
28
+ @data[:replies].map do |reply|
29
+ @reply_list << Ravelry::Comment.new(reply)
30
+ end
31
+ end
32
+ end
33
+
34
+ end
@@ -22,5 +22,18 @@ module Ravelry
22
22
  result = Utils::Request.get("yarn_weights.json", :yarn_weights)
23
23
  result.map { |yarn_weight| YarnWeight.new(yarn_weight) }
24
24
  end
25
+
26
+ # Make a GET API call for the current authenticated user. Without the OAuth setup, this will just be you, the requester.
27
+ #
28
+ # Returns a {Ravelry::User} object.
29
+ #
30
+ # Note: the returned `User` won't have everything from a standard {Ravelry::User} request, but you will have the information necessary to make a request for the full profile if desired.
31
+ #
32
+ def current_user
33
+ result = Utils::Request.get("current_user.json", :user)
34
+ user = Ravelry::User.new
35
+ user.data = result
36
+ return user
37
+ end
25
38
  end
26
39
  end
@@ -22,6 +22,17 @@ module Ravelry
22
22
  # ```
23
23
  #
24
24
  # After calling `get`, you have access to all of the class methods below.
25
+ #
26
+ # If you do not have the pattern ID, you may use the permalink:
27
+ #
28
+ # Ravelry URL: http://www.ravelry.com/patterns/library/traveling-woman
29
+ #
30
+ # Request:
31
+ #
32
+ # ```ruby
33
+ # pattern = Ravelry::Pattern.new
34
+ # pattern.permalink_get('traveling-woman')
35
+ # ```
25
36
  #
26
37
  # ##Initializing with an id
27
38
  #
@@ -96,6 +107,13 @@ module Ravelry
96
107
  #
97
108
  class Pattern < Data
98
109
 
110
+ COMMENT_OPTIONS = {
111
+ sort: ['time', 'helpful', 'time_', 'helpful_'],
112
+ page_size: 25,
113
+ include: ['highlighted_project'],
114
+ page: 1
115
+ }
116
+
99
117
  include Build
100
118
 
101
119
  attr_reader :author, :categories, :craft, :needles, :packs, :photos, :printings, :type, :yarns, :yarn_weights
@@ -108,6 +126,46 @@ module Ravelry
108
126
  @data = Utils::Request.get("patterns/#{@id}.json", :pattern)
109
127
  end
110
128
 
129
+ # Alternative method for the GET API call.
130
+ #
131
+ # Corresponds to Ravelry API endpoint `Patterns#show`
132
+ #
133
+ # Uses the pattern's Ravelry permalink instead of ID. Useful if you don't know the ID of a pattern, but have the permalink.
134
+ #
135
+ # **Example**
136
+ #
137
+ # Ravelry URL: http://www.ravelry.com/patterns/library/traveling-woman
138
+ #
139
+ # Request:
140
+ #
141
+ # ```ruby
142
+ # pattern = Ravelry::Pattern.new
143
+ # pattern.permalink_get('traveling-woman')
144
+ # ```
145
+ #
146
+ def permalink_get(permalink)
147
+ @data = Utils::Request.get("patterns/#{permalink}.json", :pattern)
148
+ end
149
+
150
+ # Get the list of comments on a pattern object.
151
+ #
152
+ # To query comments for a pattern you haven't fetched yet, without fetching the pattern:
153
+ #
154
+ # ```ruby
155
+ # pattern = Ravelry::Pattern.new
156
+ # pattern.id = "000000"
157
+ # pattern.comments
158
+ # ```
159
+ #
160
+ # To query comments for a pattern you've already fetched, follow the steps above and call `pattern.comments`.
161
+ #
162
+ def comments(options={})
163
+ @comment_list ||= []
164
+ return @comment_list if @comment_list.any?
165
+
166
+ fetch_comments(options)
167
+ end
168
+
111
169
  # Search for patterns.
112
170
  #
113
171
  # Corresponds to Ravelry API endpoint `Patterns#search`
@@ -275,7 +333,7 @@ module Ravelry
275
333
  #
276
334
  # I've included this method in case you want to have more control over how your author information is displayed.
277
335
  #
278
- # See {#build_authors} for more information about directly accessing author information.
336
+ # See {Ravelry::Author} for more information about directly accessing author information.
279
337
  #
280
338
  def pattern_author
281
339
  data[:pattern_author]
@@ -285,7 +343,7 @@ module Ravelry
285
343
  #
286
344
  # This method is included so you can access the information directly.
287
345
  #
288
- # See {#build_categories} for more information about directly accessing category information.
346
+ # See {Ravelry::Category} for more information about directly accessing category information.
289
347
  #
290
348
  def pattern_categories_raw
291
349
  data[:pattern_categories]
@@ -296,7 +354,7 @@ module Ravelry
296
354
  #
297
355
  # This method is included so you can access the information directly.
298
356
  #
299
- # See {#build_needles} for more information about directly accessing category information.
357
+ # See {Ravelry::Needle} for more information about directly accessing category information.
300
358
  #
301
359
  def pattern_needle_sizes_raw
302
360
  data[:pattern_needle_sizes]
@@ -306,7 +364,7 @@ module Ravelry
306
364
  #
307
365
  # This method is included so you can access the information directly.
308
366
  #
309
- # See {#build_pattern_type} for more information about directly accessing category information.
367
+ # See {Ravelry::Needle} for more information about directly accessing category information.
310
368
  #
311
369
  def pattern_type_raw
312
370
  data[:pattern_type]
@@ -328,7 +386,7 @@ module Ravelry
328
386
  #
329
387
  # This method is included so you can access the information directly.
330
388
  #
331
- # See {#build_photos} for more information about directly accessing category information.
389
+ # See {Ravelry::Photo} for more information about directly accessing category information.
332
390
  #
333
391
  def photos_raw
334
392
  data[:photos]
@@ -423,5 +481,16 @@ module Ravelry
423
481
  def yarn_weight_description
424
482
  data[:yarn_weight_description]
425
483
  end
484
+
485
+ private
486
+ def fetch_comments(options)
487
+ options.keep_if { |key| COMMENT_OPTIONS.keys.include?(key) }
488
+ if options[:per_page]
489
+ options[:per_page] = 100 if options[:per_page] > 100
490
+ end
491
+
492
+ comment_data = Utils::Request.get("patterns/#{@id}/comments.json", :comments, options)
493
+ comment_data.map { |comment| Comment.new(comment) }
494
+ end
426
495
  end
427
496
  end
@@ -67,11 +67,11 @@ module Ravelry
67
67
  end
68
68
 
69
69
  def about_me
70
- @data['about_me']
70
+ @data[:about_me]
71
71
  end
72
72
 
73
73
  def about_me_html
74
- @data['about_me_html']
74
+ @data[:about_me_html]
75
75
  end
76
76
 
77
77
  def author
@@ -79,45 +79,50 @@ module Ravelry
79
79
  end
80
80
 
81
81
  def fave_colors
82
- @data['fave_colors']
82
+ @data[:fave_colors]
83
83
  end
84
84
 
85
85
  def fave_curse
86
- @data['fave_curse']
86
+ @data[:fave_curse]
87
87
  end
88
88
 
89
89
  def first_name
90
- @data['first_name']
90
+ @data[:first_name]
91
91
  end
92
92
 
93
93
  def large_photo_url
94
- @data['large_photo_url']
94
+ @data[:large_photo_url]
95
95
  end
96
96
 
97
97
  def location
98
- @data['location']
98
+ @data[:location]
99
99
  end
100
100
 
101
101
  def photo_url
102
- @data['photo_url']
102
+ @data[:photo_url]
103
103
  end
104
104
 
105
105
  def small_photo_url
106
- @data['small_photo_url']
106
+ @data[:small_photo_url]
107
107
  end
108
108
 
109
109
  def tiny_photo_url
110
- @data['tiny_photo_url']
110
+ @data[:tiny_photo_url]
111
111
  end
112
112
 
113
113
  def username
114
- @data['username']
114
+ @data[:username]
115
115
  end
116
116
 
117
117
  # ID from the Ravelry database.
118
118
  #
119
119
  def _id
120
- @data['id']
120
+ @data[:id]
121
+ end
122
+
123
+ private
124
+ def build
125
+ @id = @data[:id] unless @id
121
126
  end
122
127
  end
123
128
  end
@@ -1,3 +1,3 @@
1
1
  module Ravelry
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -22,4 +22,33 @@ describe Ravelry::Misc do
22
22
  expect(result.first).to be_instance_of(Ravelry::YarnWeight)
23
23
  end
24
24
  end
25
+
26
+ context '#current_user' do
27
+ before do
28
+ @user = Ravelry::Misc.current_user
29
+ end
30
+
31
+ it 'should return a user' do
32
+ expect(@user).to be_instance_of(Ravelry::User)
33
+ end
34
+
35
+ it 'should be missing #about_me' do
36
+ expect(@user.about_me).to be_nil
37
+ end
38
+
39
+ it 'should have photos' do
40
+ expect(@user.photo_url).to be
41
+ expect(@user.small_photo_url).to be
42
+ expect(@user.tiny_photo_url).to be
43
+ expect(@user.large_photo_url).to be
44
+ end
45
+
46
+ it 'should have an id' do
47
+ expect(@user.id).to be
48
+ end
49
+
50
+ it 'should have a username' do
51
+ expect(@user.username).to be
52
+ end
53
+ end
25
54
  end
@@ -28,6 +28,26 @@ describe Ravelry::Pattern do
28
28
  end
29
29
  end
30
30
 
31
+ context "#permalink_get" do
32
+ before do
33
+ pattern = Ravelry::Pattern.new
34
+ pattern.permalink_get("traveling-woman")
35
+ @api = pattern
36
+ end
37
+
38
+ it 'should succeed' do
39
+ expect(@api).to be
40
+ end
41
+
42
+ it 'should return a pattern' do
43
+ expect(@api.data).to be
44
+ end
45
+
46
+ it 'should return a hash' do
47
+ expect(@api.data).to be_kind_of(Hash)
48
+ end
49
+ end
50
+
31
51
  context '#search' do
32
52
  let(:result) { Ravelry::Pattern.search('hello') }
33
53
  before { stub_patterns_search }
@@ -67,6 +87,16 @@ describe Ravelry::Pattern do
67
87
  end
68
88
  end
69
89
 
90
+ context '#comments' do
91
+ before do
92
+ @pattern = p_initialize_paid_with_fetch
93
+ end
94
+
95
+ it 'creates comments' do
96
+ expect(@pattern.comments[0]).to be_instance_of(Ravelry::Comment)
97
+ end
98
+ end
99
+
70
100
  context 'class methods' do
71
101
  before do
72
102
  @api = p_initialize_with_data
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ravelry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liz Abinante
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2016-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,62 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redcarpet
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: typhoeus
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
87
  - - "~>"
46
88
  - !ruby/object:Gem::Version
47
- version: '0.6'
89
+ version: '0.8'
48
90
  type: :runtime
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
- version: '0.6'
96
+ version: '0.8'
55
97
  description: Ruby gem for accessing the Ravelry API painlessly, easily, and awesomely.
56
98
  email: me@liz.codes
57
99
  executables: []
@@ -65,6 +107,7 @@ files:
65
107
  - lib/ravelry/author.rb
66
108
  - lib/ravelry/category.rb
67
109
  - lib/ravelry/color_family.rb
110
+ - lib/ravelry/comment.rb
68
111
  - lib/ravelry/configuration.rb
69
112
  - lib/ravelry/craft.rb
70
113
  - lib/ravelry/data.rb