ravelry 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CODE_OF_CONDUCT.md +40 -12
- data/README.md +5 -4
- data/lib/ravelry/needles.rb +3 -2
- data/lib/ravelry/pattern.rb +38 -1
- data/lib/ravelry/utils/build.rb +36 -36
- data/lib/ravelry/utils/request.rb +8 -3
- data/lib/ravelry/version.rb +1 -1
- data/spec/helpers/request_helpers.rb +32 -0
- data/spec/helpers/request_helpers/misc_helpers.rb +17 -0
- data/spec/helpers/request_helpers/needles_helpers.rb +24 -0
- data/spec/helpers/request_helpers/pattern_helpers.rb +17 -0
- data/spec/ravelry/misc_spec.rb +9 -1
- data/spec/ravelry/needles_spec.rb +13 -1
- data/spec/ravelry/pattern_spec.rb +42 -0
- data/spec/ravelry/utils/build_spec.rb +121 -9
- data/spec/ravelry/utils/request_spec.rb +20 -0
- data/spec/spec_helper.rb +7 -1
- metadata +12 -10
- data/.gitignore +0 -8
- data/.rspec +0 -2
- data/.ruby-version +0 -1
- data/.yardopts +0 -1
- data/Gemfile +0 -16
- data/Gemfile.lock +0 -42
- data/VERSION +0 -1
- data/ravelry.gemspec +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9132400df864b998861fc08da936fdafd7da5dc
|
4
|
+
data.tar.gz: ce313f70e9acb79289e801f5872e761d7a2a19af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1adcd5d8930d86cfa2a948995fcf54b1251d8358b16d9c6783832e60c333ddfaf5197b7857256d899d69a9676cf261523eaf2b199c58cee4eb8b76c2e0346944
|
7
|
+
data.tar.gz: 0697d617a95f2f02f31a4a0b2598ebbe7caca22bbbf2fd51be5b6e4603483dc6c8a499de4d6a0caad8aca308a3a12b995634ef9d6925f1fc5724c05833e1b4f1
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
# Contributor Code of Conduct
|
2
2
|
|
3
|
-
As contributors and maintainers of this project, and in the interest of
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
4
7
|
|
5
|
-
We are committed to making participation in this project a harassment-free
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
6
12
|
|
7
13
|
Examples of unacceptable behavior by participants include:
|
8
14
|
|
@@ -10,13 +16,35 @@ Examples of unacceptable behavior by participants include:
|
|
10
16
|
* Personal attacks
|
11
17
|
* Trolling or insulting/derogatory comments
|
12
18
|
* Public or private harassment
|
13
|
-
* Publishing other's private information, such as physical or electronic
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at [INSERT EMAIL ADDRESS]. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
|
45
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
46
|
+
version 1.3.0, available at
|
47
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
48
|
+
|
49
|
+
[homepage]: http://contributor-covenant.org
|
50
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Ravelry
|
2
2
|
|
3
|
-
_You are reading documentation for version: 0.0.
|
3
|
+
_You are reading documentation for version: 0.0.7_
|
4
4
|
|
5
|
-
[ ![Codeship Status for ArtCraftCode/ravelry](https://codeship.com/projects/fc6710e0-5719-0133-36cc-5ebc52a48109/status?branch=0.0.
|
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)
|
6
6
|
|
7
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
8
|
|
@@ -23,6 +23,7 @@ API | Endpoint | Ravelry gem class / module
|
|
23
23
|
**Needles** | [list](http://www.ravelry.com/api#needles_list) | `Ravelry::Needles.list`
|
24
24
|
**Needles** | [sizes](http://www.ravelry.com/api#needles_sizes) | `Ravelry::Needles.sizes`
|
25
25
|
**Needles** | [types](http://www.ravelry.com/api#needles_types) | `Ravelry::Needles.types`
|
26
|
+
**Patterns** | [search](http://www.ravelry.com/api#patterns_search) | `Ravelry::Pattern.search`
|
26
27
|
**Patterns** | [show](http://www.ravelry.com/api#patterns_show) | `Ravelry::Pattern.get`
|
27
28
|
**People** | [show](http://www.ravelry.com/api#people_show) | `Ravelry::User.get`
|
28
29
|
|
@@ -39,7 +40,7 @@ Hooray! You now have a gem.
|
|
39
40
|
Add to your `Gemfile`:
|
40
41
|
|
41
42
|
```ruby
|
42
|
-
gem "ravelry", "~> 0.0.
|
43
|
+
gem "ravelry", "~> 0.0.7"
|
43
44
|
```
|
44
45
|
|
45
46
|
**I highly recommend pinning your version** because the gem is in active development and I _promise_ I will break shit.
|
@@ -74,7 +75,7 @@ Ravelry.configuration.personal_key
|
|
74
75
|
|
75
76
|
# Usage
|
76
77
|
|
77
|
-
Full documentation for this gem is available [here](http://www.rubydoc.info/gems/ravelry/0.0.
|
78
|
+
Full documentation for this gem is available [here](http://www.rubydoc.info/gems/ravelry/0.0.7).
|
78
79
|
|
79
80
|
# API quirks
|
80
81
|
|
data/lib/ravelry/needles.rb
CHANGED
@@ -12,7 +12,8 @@ module Ravelry
|
|
12
12
|
# Arguments: needle type (string, optional)
|
13
13
|
#
|
14
14
|
def sizes(craft='')
|
15
|
-
result = Utils::Request
|
15
|
+
result = Utils::Request
|
16
|
+
.get('needles/sizes.json', :needle_sizes, {:craft => craft})
|
16
17
|
result.map { |needle| Needle.new(needle) }
|
17
18
|
end
|
18
19
|
|
@@ -32,4 +33,4 @@ module Ravelry
|
|
32
33
|
result.map { |needle| Needle.new(needle) }
|
33
34
|
end
|
34
35
|
end
|
35
|
-
end
|
36
|
+
end
|
data/lib/ravelry/pattern.rb
CHANGED
@@ -84,6 +84,16 @@ module Ravelry
|
|
84
84
|
#
|
85
85
|
# See the documentation for each object's available methods.
|
86
86
|
#
|
87
|
+
# # Searching
|
88
|
+
#
|
89
|
+
# To search for patterns, use the `Pattern.search` class method, which
|
90
|
+
# returns an array of patterns:
|
91
|
+
#
|
92
|
+
# ```ruby
|
93
|
+
# Ravelry::Pattern.search('socks')
|
94
|
+
# # => [#<Pattern>, ...]
|
95
|
+
# ```
|
96
|
+
#
|
87
97
|
class Pattern < Data
|
88
98
|
|
89
99
|
include Build
|
@@ -98,6 +108,33 @@ module Ravelry
|
|
98
108
|
@data = Utils::Request.get("patterns/#{@id}.json", :pattern)
|
99
109
|
end
|
100
110
|
|
111
|
+
# Search for patterns.
|
112
|
+
#
|
113
|
+
# Corresponds to Ravelry API endpoint `Patterns#search`
|
114
|
+
#
|
115
|
+
# @param query [String] required
|
116
|
+
# @option options [Boolean] :personal_attributes
|
117
|
+
# @option options [Integer] :page
|
118
|
+
# @option options [Integer] :page_size
|
119
|
+
# @return [Array<Pattern>] an array of `Pattern`s
|
120
|
+
def self.search(query, options={})
|
121
|
+
params = {query: query}
|
122
|
+
params.merge!(options)
|
123
|
+
|
124
|
+
unless params[:personal_attributes].nil?
|
125
|
+
params[:personal_attributes] = (params[:personal_attributes] ? 1 : 0)
|
126
|
+
end
|
127
|
+
|
128
|
+
patterns = Utils::Request
|
129
|
+
.get("patterns/search.json", :patterns, params)
|
130
|
+
|
131
|
+
patterns.map do |data|
|
132
|
+
pattern = Ravelry::Pattern.new
|
133
|
+
pattern.data = data
|
134
|
+
pattern
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
101
138
|
# Creates all objects associated with your pattern; returns nothing; sets `attr_readers`.
|
102
139
|
#
|
103
140
|
def build
|
@@ -387,4 +424,4 @@ module Ravelry
|
|
387
424
|
data[:yarn_weight_description]
|
388
425
|
end
|
389
426
|
end
|
390
|
-
end
|
427
|
+
end
|
data/lib/ravelry/utils/build.rb
CHANGED
@@ -9,7 +9,11 @@ module Ravelry
|
|
9
9
|
# See {Ravelry::Author} for more information.
|
10
10
|
#
|
11
11
|
def self.author(data)
|
12
|
-
|
12
|
+
if data[:pattern_author]
|
13
|
+
@author = Author.new(data[:pattern_author])
|
14
|
+
else
|
15
|
+
@author = nil
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
# Creates and returns an array of {Ravelry::Category} objects.
|
@@ -17,11 +21,9 @@ module Ravelry
|
|
17
21
|
# See {Ravelry::Category} for more information.
|
18
22
|
#
|
19
23
|
def self.categories(data)
|
20
|
-
@categories = []
|
21
|
-
|
22
|
-
@categories << Category.new(cat)
|
24
|
+
@categories = data.fetch(:pattern_categories, []).map do |cat|
|
25
|
+
Category.new(cat)
|
23
26
|
end
|
24
|
-
@categories
|
25
27
|
end
|
26
28
|
|
27
29
|
# Creates and returns a {Ravelry::Craft} object.
|
@@ -29,7 +31,11 @@ module Ravelry
|
|
29
31
|
# See {Ravelry::Craft} for more information.
|
30
32
|
#
|
31
33
|
def self.craft(data)
|
32
|
-
|
34
|
+
if data[:craft]
|
35
|
+
@craft = Craft.new(data[:craft])
|
36
|
+
else
|
37
|
+
@craft = nil
|
38
|
+
end
|
33
39
|
end
|
34
40
|
|
35
41
|
# Creates and returns an array of {Ravelry::Needle} objects.
|
@@ -39,11 +45,9 @@ module Ravelry
|
|
39
45
|
# See {Ravelry::Needle} for more information.
|
40
46
|
#
|
41
47
|
def self.needles(data)
|
42
|
-
@needles = []
|
43
|
-
|
44
|
-
@needles << Needle.new(ndl)
|
48
|
+
@needles = data.fetch(:pattern_needle_sizes, []).map do |ndl|
|
49
|
+
Needle.new(ndl)
|
45
50
|
end
|
46
|
-
@needles
|
47
51
|
end
|
48
52
|
|
49
53
|
# Creates and returns an array of {Ravelry::Pack} objects.
|
@@ -51,13 +55,11 @@ module Ravelry
|
|
51
55
|
# See {Ravelry::Pack} for more information.
|
52
56
|
#
|
53
57
|
def self.packs(data)
|
54
|
-
@packs = []
|
55
|
-
data[:packs].each do |pack_data|
|
58
|
+
@packs = data.fetch(:packs, []).map do |pack_data|
|
56
59
|
pack = Pack.new
|
57
60
|
pack.data = pack_data
|
58
|
-
|
61
|
+
pack
|
59
62
|
end
|
60
|
-
@packs
|
61
63
|
end
|
62
64
|
|
63
65
|
# Creates and returns a {Ravelry::PatternType} object.
|
@@ -67,7 +69,11 @@ module Ravelry
|
|
67
69
|
# See {Ravelry::PatternType} for more information.
|
68
70
|
#
|
69
71
|
def self.pattern_type(data)
|
70
|
-
|
72
|
+
if data[:pattern_type]
|
73
|
+
@pattern_type = PatternType.new(data[:pattern_type])
|
74
|
+
else
|
75
|
+
@pattern_type = nil
|
76
|
+
end
|
71
77
|
end
|
72
78
|
|
73
79
|
# Creates and returns an array of {Ravelry::Photo} objects.
|
@@ -75,13 +81,11 @@ module Ravelry
|
|
75
81
|
# See {Ravelry::Photo} for more information.
|
76
82
|
#
|
77
83
|
def self.photos(data)
|
78
|
-
@photos = []
|
79
|
-
data[:photos].each do |photo_data|
|
84
|
+
@photos = data.fetch(:photos, []).map do |photo_data|
|
80
85
|
photo = Photo.new(photo_data[:id])
|
81
86
|
photo.data = photo_data
|
82
|
-
|
87
|
+
photo
|
83
88
|
end
|
84
|
-
@photos
|
85
89
|
end
|
86
90
|
|
87
91
|
# Creates and returns an array of {Ravelry::Printing} objects.
|
@@ -89,11 +93,9 @@ module Ravelry
|
|
89
93
|
# See {Ravelry::Printing} for more information.
|
90
94
|
#
|
91
95
|
def self.printings(data)
|
92
|
-
@printings = []
|
93
|
-
|
94
|
-
@printings << Printing.new(printing_data)
|
96
|
+
@printings = data.fetch(:printings, []).map do |printing_data|
|
97
|
+
Printing.new(printing_data)
|
95
98
|
end
|
96
|
-
@printings
|
97
99
|
end
|
98
100
|
|
99
101
|
# Creates and returns an array of {Ravelry::UserSite} objects.
|
@@ -101,11 +103,9 @@ module Ravelry
|
|
101
103
|
# See {Ravelry::UserSite} for more information.
|
102
104
|
#
|
103
105
|
def self.user_sites(data)
|
104
|
-
@user_sites = []
|
105
|
-
|
106
|
-
@user_sites << UserSite.new(site)
|
106
|
+
@user_sites = data.fetch(:user_sites, []).map do |site|
|
107
|
+
UserSite.new(site)
|
107
108
|
end
|
108
|
-
@user_sites
|
109
109
|
end
|
110
110
|
|
111
111
|
# Creates and returns an array of {Ravelry::Yarn} objects.
|
@@ -113,13 +113,13 @@ module Ravelry
|
|
113
113
|
# See {Ravelry::Yarn} for more information.
|
114
114
|
#
|
115
115
|
def self.yarns(data)
|
116
|
-
|
117
|
-
|
116
|
+
packs = data.fetch(:packs, []).select { |pack| pack[:yarn] }
|
117
|
+
|
118
|
+
@yarns = packs.map do |pack|
|
118
119
|
yarn = Yarn.new
|
119
|
-
yarn.data =
|
120
|
-
|
120
|
+
yarn.data = pack[:yarn]
|
121
|
+
yarn
|
121
122
|
end
|
122
|
-
@yarns
|
123
123
|
end
|
124
124
|
|
125
125
|
# Creates and returns an array of {Ravelry::YarnWeight} objects.
|
@@ -127,13 +127,13 @@ module Ravelry
|
|
127
127
|
# See {Ravelry::YarnWeight} for more information.
|
128
128
|
#
|
129
129
|
def self.yarn_weights(data)
|
130
|
-
|
131
|
-
|
130
|
+
packs = data.fetch(:packs, []).select { |pack| pack[:yarn_weight] }
|
131
|
+
|
132
|
+
@yarn_weights = packs.map do |pack|
|
132
133
|
yarn_weight = YarnWeight.new
|
133
134
|
yarn_weight.data = pack[:yarn_weight]
|
134
|
-
|
135
|
+
yarn_weight
|
135
136
|
end
|
136
|
-
@yarn_weights
|
137
137
|
end
|
138
138
|
|
139
139
|
end
|
@@ -3,12 +3,17 @@ module Ravelry
|
|
3
3
|
module Request
|
4
4
|
extend self
|
5
5
|
|
6
|
-
def get(url, key)
|
7
|
-
request = Typhoeus::Request.get(
|
6
|
+
def get(url, key, params={})
|
7
|
+
request = Typhoeus::Request.get(
|
8
|
+
"https://api.ravelry.com/#{url}",
|
9
|
+
userpwd: "#{Ravelry.configuration.access_key}:#{Ravelry.configuration.personal_key}",
|
10
|
+
params: params
|
11
|
+
)
|
12
|
+
|
8
13
|
data = JSON.parse(request.response_body, {symbolize_names: true})
|
9
14
|
return data[key] if key
|
10
15
|
return data
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
14
|
-
end
|
19
|
+
end
|
data/lib/ravelry/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'request_helpers/misc_helpers'
|
2
|
+
require_relative 'request_helpers/needles_helpers'
|
3
|
+
require_relative 'request_helpers/pattern_helpers'
|
4
|
+
|
5
|
+
module RequestHelpers
|
6
|
+
# Helpers that stub API requests
|
7
|
+
|
8
|
+
# Stubs a Typhoeus request with a response fixture
|
9
|
+
#
|
10
|
+
def stub_request_with_fixture(url_or_pattern, file)
|
11
|
+
response = fixture_response(file)
|
12
|
+
Typhoeus.stub(url_or_pattern).and_return(response)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a Typhoeus::Response with the given fixture as the body
|
16
|
+
#
|
17
|
+
def fixture_response(file)
|
18
|
+
Typhoeus::Response.new(code: 200, body: fixture(file))
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def fixture(file)
|
23
|
+
File.read(fixture_path(file))
|
24
|
+
end
|
25
|
+
|
26
|
+
def fixture_path(file)
|
27
|
+
File.expand_path(
|
28
|
+
"request_helpers/fixtures/#{file}",
|
29
|
+
File.dirname(__FILE__)
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RequestHelpers
|
2
|
+
# Helpers that stub out requests to misc endpoints
|
3
|
+
|
4
|
+
def stub_color_families
|
5
|
+
stub_request_with_fixture(
|
6
|
+
%r{/color_families\.json},
|
7
|
+
'color_families.json'
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
def stub_yarn_weights
|
12
|
+
stub_request_with_fixture(
|
13
|
+
%r{/yarn_weights\.json},
|
14
|
+
'yarn_weights.json'
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RequestHelpers
|
2
|
+
# Helpers that stub out requests to needles endpoints
|
3
|
+
|
4
|
+
def stub_needles_sizes
|
5
|
+
stub_request_with_fixture(
|
6
|
+
%r{/needles/sizes\.json},
|
7
|
+
'needles_sizes.json'
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
def stub_needles_types
|
12
|
+
stub_request_with_fixture(
|
13
|
+
%r{/needles/types\.json},
|
14
|
+
'needles_types.json'
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def stub_needles_list
|
19
|
+
stub_request_with_fixture(
|
20
|
+
%r{/people/[^/]+/needles/list\.json},
|
21
|
+
'needles_list.json'
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RequestHelpers
|
2
|
+
# Helpers that stub out requests to pattern endpoints
|
3
|
+
|
4
|
+
def stub_patterns_show_paid
|
5
|
+
stub_request_with_fixture(
|
6
|
+
%r{/patterns/[0-9]+\.json},
|
7
|
+
'patterns_show_paid.json'
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
def stub_patterns_search
|
12
|
+
stub_request_with_fixture(
|
13
|
+
%r{/patterns/search.json},
|
14
|
+
'patterns_search.json'
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
data/spec/ravelry/misc_spec.rb
CHANGED
@@ -2,6 +2,10 @@ require_relative '../spec_helper'
|
|
2
2
|
|
3
3
|
describe Ravelry::Misc do
|
4
4
|
context '#color_families' do
|
5
|
+
before do
|
6
|
+
stub_color_families
|
7
|
+
end
|
8
|
+
|
5
9
|
it 'should return an array of color families' do
|
6
10
|
result = Ravelry::Misc.color_families
|
7
11
|
expect(result.first).to be_instance_of(Ravelry::ColorFamily)
|
@@ -9,9 +13,13 @@ describe Ravelry::Misc do
|
|
9
13
|
end
|
10
14
|
|
11
15
|
context '#yarn_weights' do
|
16
|
+
before do
|
17
|
+
stub_yarn_weights
|
18
|
+
end
|
19
|
+
|
12
20
|
it 'should return an array of color families' do
|
13
21
|
result = Ravelry::Misc.yarn_weights
|
14
22
|
expect(result.first).to be_instance_of(Ravelry::YarnWeight)
|
15
23
|
end
|
16
24
|
end
|
17
|
-
end
|
25
|
+
end
|
@@ -2,6 +2,10 @@ require_relative '../spec_helper'
|
|
2
2
|
|
3
3
|
describe Ravelry::Needles do
|
4
4
|
context '#sizes' do
|
5
|
+
before do
|
6
|
+
stub_needles_sizes
|
7
|
+
end
|
8
|
+
|
5
9
|
it 'should return an array of needles' do
|
6
10
|
result = Ravelry::Needles.sizes
|
7
11
|
expect(result.first).to be_instance_of(Ravelry::Needle)
|
@@ -9,6 +13,10 @@ describe Ravelry::Needles do
|
|
9
13
|
end
|
10
14
|
|
11
15
|
context '#types' do
|
16
|
+
before do
|
17
|
+
stub_needles_types
|
18
|
+
end
|
19
|
+
|
12
20
|
it 'should return an array of needles' do
|
13
21
|
result = Ravelry::Needles.types
|
14
22
|
expect(result.first).to be_instance_of(Ravelry::Needle)
|
@@ -16,9 +24,13 @@ describe Ravelry::Needles do
|
|
16
24
|
end
|
17
25
|
|
18
26
|
context '#list' do
|
27
|
+
before do
|
28
|
+
stub_needles_list
|
29
|
+
end
|
30
|
+
|
19
31
|
it 'should return an array of needles' do
|
20
32
|
result = Ravelry::Needles.list("feministy")
|
21
33
|
expect(result.first).to be_instance_of(Ravelry::Needle)
|
22
34
|
end
|
23
35
|
end
|
24
|
-
end
|
36
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
2
|
|
3
3
|
describe Ravelry::Pattern do
|
4
|
+
before do
|
5
|
+
stub_patterns_show_paid
|
6
|
+
end
|
4
7
|
|
5
8
|
it 'should be an instance of Patterns' do
|
6
9
|
pattern = p_initialize_paid_with_fetch
|
@@ -25,6 +28,45 @@ describe Ravelry::Pattern do
|
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
31
|
+
context '#search' do
|
32
|
+
let(:result) { Ravelry::Pattern.search('hello') }
|
33
|
+
before { stub_patterns_search }
|
34
|
+
|
35
|
+
it 'should succeed' do
|
36
|
+
expect(result).to be
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should send a request to /patterns/search.json' do
|
40
|
+
expect(Ravelry::Utils::Request).to receive(:get)
|
41
|
+
.with('patterns/search.json', :patterns, {:query => 'hello'})
|
42
|
+
.and_call_original
|
43
|
+
|
44
|
+
Ravelry::Pattern.search('hello')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should set params' do
|
48
|
+
expect(Ravelry::Utils::Request).to receive(:get)
|
49
|
+
.with('patterns/search.json', :patterns, {
|
50
|
+
:query => 'hello',
|
51
|
+
:personal_attributes => 1,
|
52
|
+
:page => 123,
|
53
|
+
:page_size => 2
|
54
|
+
})
|
55
|
+
.and_call_original
|
56
|
+
|
57
|
+
Ravelry::Pattern
|
58
|
+
.search('hello', personal_attributes: true, page: 123, page_size: 2)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should return an array' do
|
62
|
+
expect(result).to be_kind_of(Array)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should return an array of Patterns' do
|
66
|
+
expect(result[0]).to be_kind_of(Ravelry::Pattern)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
28
70
|
context 'class methods' do
|
29
71
|
before do
|
30
72
|
@api = p_initialize_with_data
|
@@ -13,6 +13,16 @@ describe Ravelry::Build do
|
|
13
13
|
it 'returns an instance of Author' do
|
14
14
|
expect(@author).to be_instance_of(Ravelry::Author)
|
15
15
|
end
|
16
|
+
|
17
|
+
context 'without an author' do
|
18
|
+
before do
|
19
|
+
@author = Ravelry::Build.author({})
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns nil' do
|
23
|
+
expect(@author).to be(nil)
|
24
|
+
end
|
25
|
+
end
|
16
26
|
end
|
17
27
|
|
18
28
|
context '#categories' do
|
@@ -35,6 +45,16 @@ describe Ravelry::Build do
|
|
35
45
|
it 'returns an array with Category objects' do
|
36
46
|
expect(@categories[0]).to be_instance_of(Ravelry::Category)
|
37
47
|
end
|
48
|
+
|
49
|
+
context 'without categories' do
|
50
|
+
before do
|
51
|
+
@categories = Ravelry::Build.categories({})
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns an empty array' do
|
55
|
+
expect(@categories).to eql([])
|
56
|
+
end
|
57
|
+
end
|
38
58
|
end
|
39
59
|
|
40
60
|
context '#craft' do
|
@@ -49,6 +69,16 @@ describe Ravelry::Build do
|
|
49
69
|
it 'returns an instance of Craft' do
|
50
70
|
expect(@craft).to be_instance_of(Ravelry::Craft)
|
51
71
|
end
|
72
|
+
|
73
|
+
context 'without a craft' do
|
74
|
+
before do
|
75
|
+
@craft = Ravelry::Build.craft({})
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns nil' do
|
79
|
+
expect(@craft).to be(nil)
|
80
|
+
end
|
81
|
+
end
|
52
82
|
end
|
53
83
|
|
54
84
|
context '#needles' do
|
@@ -67,6 +97,16 @@ describe Ravelry::Build do
|
|
67
97
|
it 'returns an Array of Needle objects' do
|
68
98
|
expect(@needles[0]).to be_instance_of(Ravelry::Needle)
|
69
99
|
end
|
100
|
+
|
101
|
+
context 'without needles' do
|
102
|
+
before do
|
103
|
+
@needles = Ravelry::Build.needles({})
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'returns an empty array' do
|
107
|
+
expect(@needles).to eql([])
|
108
|
+
end
|
109
|
+
end
|
70
110
|
end
|
71
111
|
|
72
112
|
context '#packs' do
|
@@ -89,6 +129,40 @@ describe Ravelry::Build do
|
|
89
129
|
it 'returns an Array of Pack objects' do
|
90
130
|
expect(@packs[0]).to be_instance_of(Ravelry::Pack)
|
91
131
|
end
|
132
|
+
|
133
|
+
context 'without packs' do
|
134
|
+
before do
|
135
|
+
@packs = Ravelry::Build.packs({})
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'returns an empty array' do
|
139
|
+
expect(@packs).to eql([])
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context '#pattern_type' do
|
145
|
+
before do
|
146
|
+
@type = Ravelry::Build.pattern_type(paid_pattern_stub)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'exists' do
|
150
|
+
expect(@type).to be_true
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'returns an instance of Type' do
|
154
|
+
expect(@type).to be_instance_of(Ravelry::PatternType)
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'without a type' do
|
158
|
+
before do
|
159
|
+
@type = Ravelry::Build.pattern_type({})
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'returns nil' do
|
163
|
+
expect(@type).to be(nil)
|
164
|
+
end
|
165
|
+
end
|
92
166
|
end
|
93
167
|
|
94
168
|
context '#photos' do
|
@@ -107,6 +181,16 @@ describe Ravelry::Build do
|
|
107
181
|
it 'returns an array of Photo objects' do
|
108
182
|
expect(@photos[0]).to be_instance_of(Ravelry::Photo)
|
109
183
|
end
|
184
|
+
|
185
|
+
context 'without photos' do
|
186
|
+
before do
|
187
|
+
@photos = Ravelry::Build.photos({})
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'returns an empty array' do
|
191
|
+
expect(@photos).to eql([])
|
192
|
+
end
|
193
|
+
end
|
110
194
|
end
|
111
195
|
|
112
196
|
context '#printings' do
|
@@ -125,19 +209,27 @@ describe Ravelry::Build do
|
|
125
209
|
it 'returns an array with Printing objects' do
|
126
210
|
expect(@printings[0]).to be_instance_of(Ravelry::Printing)
|
127
211
|
end
|
128
|
-
end
|
129
212
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
213
|
+
context 'without printings' do
|
214
|
+
before do
|
215
|
+
@printings = Ravelry::Build.printings({})
|
216
|
+
end
|
134
217
|
|
135
|
-
|
136
|
-
|
218
|
+
it 'returns an empty array' do
|
219
|
+
expect(@printings).to eql([])
|
220
|
+
end
|
137
221
|
end
|
222
|
+
end
|
138
223
|
|
139
|
-
|
140
|
-
|
224
|
+
context '#user_sites' do
|
225
|
+
context 'without user sites' do
|
226
|
+
before do
|
227
|
+
@user_sites = Ravelry::Build.user_sites({})
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'returns an empty array' do
|
231
|
+
expect(@user_sites).to eql([])
|
232
|
+
end
|
141
233
|
end
|
142
234
|
end
|
143
235
|
|
@@ -161,6 +253,16 @@ describe Ravelry::Build do
|
|
161
253
|
it 'returns an array of Yarn objects' do
|
162
254
|
expect(@yarns[0]).to be_instance_of(Ravelry::Yarn)
|
163
255
|
end
|
256
|
+
|
257
|
+
context 'without yarns' do
|
258
|
+
before do
|
259
|
+
@yarns = Ravelry::Build.yarns({})
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'returns an empty array' do
|
263
|
+
expect(@yarns).to eql([])
|
264
|
+
end
|
265
|
+
end
|
164
266
|
end
|
165
267
|
|
166
268
|
context '#yarn_weights' do
|
@@ -183,5 +285,15 @@ describe Ravelry::Build do
|
|
183
285
|
it 'returns an array of YarnWeight objects' do
|
184
286
|
expect(@yw[0]).to be_instance_of(Ravelry::YarnWeight)
|
185
287
|
end
|
288
|
+
|
289
|
+
context 'without yarn weights' do
|
290
|
+
before do
|
291
|
+
@yw = Ravelry::Build.yarn_weights({})
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'returns an empty array' do
|
295
|
+
expect(@yw).to eql([])
|
296
|
+
end
|
297
|
+
end
|
186
298
|
end
|
187
299
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe Ravelry::Utils::Request do
|
4
|
+
let(:response) { double(:response_body => '{}') }
|
5
|
+
let(:url) { 'current_user.json' }
|
6
|
+
let(:userpwd) do
|
7
|
+
"#{Ravelry.configuration.access_key}:#{Ravelry.configuration.personal_key}"
|
8
|
+
end
|
9
|
+
let(:params) { {test: 123} }
|
10
|
+
|
11
|
+
context '#get' do
|
12
|
+
it 'passes in query params' do
|
13
|
+
expect(Typhoeus::Request).to receive(:get)
|
14
|
+
.with("https://api.ravelry.com/#{url}", userpwd: userpwd, params: params)
|
15
|
+
.and_return(response)
|
16
|
+
|
17
|
+
Ravelry::Utils::Request.get(url, nil, params)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative 'helpers/pattern_helpers'
|
|
8
8
|
require_relative 'helpers/pack_helpers'
|
9
9
|
require_relative 'helpers/yarn_helpers'
|
10
10
|
require_relative 'helpers/yarn_weight_helpers'
|
11
|
+
require_relative 'helpers/request_helpers'
|
11
12
|
|
12
13
|
# Requires supporting files with custom matchers and macros, etc,
|
13
14
|
# in ./support/ and its subdirectories.
|
@@ -19,6 +20,7 @@ RSpec.configure do |config|
|
|
19
20
|
config.include PackHelpers
|
20
21
|
config.include YarnHelpers
|
21
22
|
config.include YarnWeightHelpers
|
23
|
+
config.include RequestHelpers
|
22
24
|
config.order = "random"
|
23
25
|
config.before(:all) do
|
24
26
|
Ravelry.configure do |config|
|
@@ -27,4 +29,8 @@ RSpec.configure do |config|
|
|
27
29
|
config.personal_key = ENV['RAV_PERSONAL']
|
28
30
|
end
|
29
31
|
end
|
30
|
-
|
32
|
+
|
33
|
+
config.before(:each) do
|
34
|
+
Typhoeus::Expectation.clear
|
35
|
+
end
|
36
|
+
end
|
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.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liz Abinante
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,16 +58,9 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
-
- ".gitignore"
|
62
|
-
- ".rspec"
|
63
|
-
- ".ruby-version"
|
64
|
-
- ".yardopts"
|
65
61
|
- CODE_OF_CONDUCT.md
|
66
|
-
- Gemfile
|
67
|
-
- Gemfile.lock
|
68
62
|
- LICENSE.txt
|
69
63
|
- README.md
|
70
|
-
- VERSION
|
71
64
|
- lib/ravelry.rb
|
72
65
|
- lib/ravelry/author.rb
|
73
66
|
- lib/ravelry/category.rb
|
@@ -92,10 +85,13 @@ files:
|
|
92
85
|
- lib/ravelry/version.rb
|
93
86
|
- lib/ravelry/yarn.rb
|
94
87
|
- lib/ravelry/yarn_weight.rb
|
95
|
-
- ravelry.gemspec
|
96
88
|
- spec/helpers/helpers.rb
|
97
89
|
- spec/helpers/pack_helpers.rb
|
98
90
|
- spec/helpers/pattern_helpers.rb
|
91
|
+
- spec/helpers/request_helpers.rb
|
92
|
+
- spec/helpers/request_helpers/misc_helpers.rb
|
93
|
+
- spec/helpers/request_helpers/needles_helpers.rb
|
94
|
+
- spec/helpers/request_helpers/pattern_helpers.rb
|
99
95
|
- spec/helpers/yarn_helpers.rb
|
100
96
|
- spec/helpers/yarn_weight_helpers.rb
|
101
97
|
- spec/ravelry/author_spec.rb
|
@@ -112,6 +108,7 @@ files:
|
|
112
108
|
- spec/ravelry/printing_spec.rb
|
113
109
|
- spec/ravelry/user_spec.rb
|
114
110
|
- spec/ravelry/utils/build_spec.rb
|
111
|
+
- spec/ravelry/utils/request_spec.rb
|
115
112
|
- spec/ravelry/yarn_spec.rb
|
116
113
|
- spec/ravelry/yarn_weight_spec.rb
|
117
114
|
- spec/ravelry_spec.rb
|
@@ -144,6 +141,10 @@ test_files:
|
|
144
141
|
- spec/helpers/helpers.rb
|
145
142
|
- spec/helpers/pack_helpers.rb
|
146
143
|
- spec/helpers/pattern_helpers.rb
|
144
|
+
- spec/helpers/request_helpers/misc_helpers.rb
|
145
|
+
- spec/helpers/request_helpers/needles_helpers.rb
|
146
|
+
- spec/helpers/request_helpers/pattern_helpers.rb
|
147
|
+
- spec/helpers/request_helpers.rb
|
147
148
|
- spec/helpers/yarn_helpers.rb
|
148
149
|
- spec/helpers/yarn_weight_helpers.rb
|
149
150
|
- spec/ravelry/author_spec.rb
|
@@ -160,6 +161,7 @@ test_files:
|
|
160
161
|
- spec/ravelry/printing_spec.rb
|
161
162
|
- spec/ravelry/user_spec.rb
|
162
163
|
- spec/ravelry/utils/build_spec.rb
|
164
|
+
- spec/ravelry/utils/request_spec.rb
|
163
165
|
- spec/ravelry/yarn_spec.rb
|
164
166
|
- spec/ravelry/yarn_weight_spec.rb
|
165
167
|
- spec/ravelry_spec.rb
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.1.2
|
data/.yardopts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--markup markdown
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,42 +0,0 @@
|
|
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/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.6
|
data/ravelry.gemspec
DELETED
@@ -1,28 +0,0 @@
|
|
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 = "2015-11-10"
|
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
|
-
spec.required_ruby_version = '>= 2.0.0'
|
18
|
-
|
19
|
-
spec.files = `git ls-files -z`.split("\x0")
|
20
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
-
spec.require_paths = ["lib"]
|
23
|
-
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
-
spec.add_dependency "typhoeus", "~> 0.6"
|
27
|
-
end
|
28
|
-
|