ravelry 0.0.2 → 0.0.4

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: a1b76548617aae144d81b8e817628c3175318335
4
- data.tar.gz: ebcaa555d469c033819943bf99cc3b0d37bac694
3
+ metadata.gz: 4dcc5188a55d99529661b1bde3859b5ea1351da5
4
+ data.tar.gz: c526d13944150e9464254ea8d7a3a8296249d1eb
5
5
  SHA512:
6
- metadata.gz: 792ab50c08765510de23fc44b2f0cf249cbdbee1a749c74528b0d1b4ec312d54d8b5c9e42852a20d2d2280ed348796983e2ca1121f7b08b3215c1d5540fb4b92
7
- data.tar.gz: 2528c825060b46dcceb986985ec91f3dfcde5b8b0f374ccfe049a853eae9bef74e1a036ffa5b85cc6c6ccfff65d2f7646d0ab4917341e42ecde8b13682f1f60d
6
+ metadata.gz: 8ecae4dc95317877ea9f9e80d5ca9ff49adab6bd79a95da7dc634eb3b49d901348de809d5f48268c9ee64741b4dbece5f9c38cc5c045a15c33edd68d8d2b1be1
7
+ data.tar.gz: 1bb66e52e6f80a1512586974e4841233bca9d89226fb369d63cb37699ecf85b9ccdd1fa39662940fb8457c6a5f3416d5645c436496076ff217bfe3203ecee3c6
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # Ravelry
2
2
 
3
- _You are reading documentation for version: 0.0.2_
3
+ _You are reading documentation for version: 0.0.4_
4
4
 
5
- [ ![Codeship Status for ArtCraftCode/ravelry](https://codeship.com/projects/fc6710e0-5719-0133-36cc-5ebc52a48109/status?branch=0.0.2)](https://codeship.com/projects/109462)
5
+ You may be wondering what happened to 0.0.3. Apparently, I don't understand how publishing works. LOL WHOOOOOPS.
6
+
7
+ [ ![Codeship Status for ArtCraftCode/ravelry](https://codeship.com/projects/fc6710e0-5719-0133-36cc-5ebc52a48109/status?branch=0.0.4)](https://codeship.com/projects/109462)
6
8
 
7
9
  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
10
 
@@ -14,7 +16,8 @@ Ravelry API documentation is currently available [here](http://www.ravelry.com/a
14
16
 
15
17
  ## API coverage
16
18
 
17
- * `Patterns#show` (`GET`)
19
+ * [`Patterns#show`](http://www.ravelry.com/api#patterns_show) maps to `Ravelry::Pattern`
20
+ * [`People#show`](http://www.ravelry.com/api#people_show) maps to `Ravelry::User`
18
21
 
19
22
  # Installation
20
23
 
@@ -28,8 +31,8 @@ Hooray! You now have a gem.
28
31
 
29
32
  Add to your `Gemfile`:
30
33
 
31
- ```
32
- gem "ravelry", "~> 0.0.2"
34
+ ```ruby
35
+ gem "ravelry", "~> 0.0.4"
33
36
  ```
34
37
 
35
38
  **I highly recommend pinning your version** because the gem is in active development and I _promise_ I will break shit.
@@ -54,9 +57,17 @@ end
54
57
 
55
58
  Getting these keys requires a (free) Ravelry account and that you agree to the terms of use for the API.
56
59
 
60
+ The keys are available to you throughout your application as:
61
+
62
+ ```ruby
63
+ Ravelry.configuration.access_key
64
+ Ravelry.configuration.secret_key
65
+ Ravelry.configuration.personal_key
66
+ ```
67
+
57
68
  # Usage
58
69
 
59
- Full documentation for this gem is available [here](http://www.rubydoc.info/gems/ravelry/0.0.2).
70
+ Full documentation for this gem is available [here](http://www.rubydoc.info/gems/ravelry/0.0.4).
60
71
 
61
72
  # API quirks
62
73
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.4
@@ -16,6 +16,9 @@ require 'ravelry/pattern_needle'
16
16
  require 'ravelry/pattern_type'
17
17
  require 'ravelry/photo'
18
18
  require 'ravelry/printing'
19
+ require 'ravelry/social_site'
20
+ require 'ravelry/user'
21
+ require 'ravelry/user_site'
19
22
  require 'ravelry/yarn'
20
23
  require 'ravelry/yarn_weight'
21
24
 
@@ -93,7 +93,7 @@ module Ravelry
93
93
  # Handles GET API call and parses JSON response.
94
94
  #
95
95
  def get
96
- request = Typhoeus::Request.get("https://api.ravelry.com/patterns/#{@id}.json", userpwd: "#{ENV['RAV_ACCESS']}:#{ENV['RAV_PERSONAL']}")
96
+ request = Typhoeus::Request.get("https://api.ravelry.com/patterns/#{@id}.json", userpwd: "#{Ravelry.configuration.access_key}:#{Ravelry.configuration.personal_key}")
97
97
  result = JSON.parse(request.response_body, {symbolize_names: true})
98
98
  @data = result[:pattern]
99
99
  end
@@ -0,0 +1,22 @@
1
+ module Ravelry
2
+ # There is no API access point for PatternAuthors. The information used to create `Ravelry::SocialSite` comes from other objects.
3
+ #
4
+ # You should not create `Author` objects manually; they are all created–and owned by–other objects.
5
+ #
6
+ # This does not inherit from {Ravelry::Data} because it doesn't have a corresponding API endpoint.
7
+ #
8
+ class SocialSite
9
+ attr_reader :id, :active, :favicon_url, :name
10
+
11
+ # Creates new `SocialSite` from Ravelry API attributes.
12
+ #
13
+ # All class variables are readonly.
14
+ #
15
+ def initialize(social_site)
16
+ @id = social_site[:id]
17
+ @active = social_site[:active]
18
+ @favicon_url = social_site[:favicon_url]
19
+ @name = social_site[:name]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,123 @@
1
+ module Ravelry
2
+ # `Ravelry::User` corresponds to User objects in Ravelry and the `People#show` endpoint.
3
+ #
4
+ # This class requires your environment variables be set (see {file:README.md README}). API calls are authenticated using HTTP Basic Auth unless otherwise noted.
5
+ #
6
+ # #User objects
7
+ #
8
+ # To create an empty object:
9
+ #
10
+ # ```ruby
11
+ # user = Ravelry::User.new
12
+ # ```
13
+ #
14
+ # To complete the `GET` request, set the `id` (this is the desired user's username) and run:
15
+ #
16
+ # ```ruby
17
+ # user.id = "feministy"
18
+ # user.get
19
+ # ```
20
+ #
21
+ # After calling `get`, you have access to all of the class methods below.
22
+ #
23
+ # ##Initializing with an id
24
+ #
25
+ # Optionally, you can initialize with an id:
26
+ #
27
+ # ```ruby
28
+ # user = Ravelry::User.new(id)
29
+ # ```
30
+ #
31
+ # And then run your get request:
32
+ #
33
+ # ```ruby
34
+ # user.get
35
+ # ```
36
+ #
37
+ # Upon completing the `get` request, all of your objects and methods will ready to use!
38
+ #
39
+ # ##Loading existing user data
40
+ #
41
+ # If you have existing user data, you should initialize as follows:
42
+ #
43
+ # ```ruby
44
+ # user = Ravelry::User.new
45
+ # user.data = my_data
46
+ # ```
47
+ #
48
+ # You now have access to all class methods for your user. Be warned: if you run `get` again, you will override your data with fresh information from the API call.
49
+ #
50
+ # This will create the following objects and readers from the existing `data`:
51
+ #
52
+ # * `user.pattern_author` (alias: `user.author`) - a {Ravelry::Author} object
53
+ # * `user.user_sites` - an array of {Ravelry::UserSite} objects
54
+ #
55
+ # See the documentation for each object's available methods.
56
+ #
57
+ class User < Data
58
+ attr_reader :pattern_author, :user_sites
59
+
60
+ def get
61
+ request = Typhoeus::Request.get("https://api.ravelry.com/people/#{@id}.json", userpwd: "#{Ravelry.configuration.access_key}:#{Ravelry.configuration.personal_key}")
62
+ result = JSON.parse(request.response_body, {symbolize_names: true})
63
+ @data = result[:user]
64
+ @pattern_author = Build.author(@data)
65
+ @user_sites = Build.user_sites(@data)
66
+ self
67
+ end
68
+
69
+ def about_me
70
+ @data['about_me']
71
+ end
72
+
73
+ def about_me_html
74
+ @data['about_me_html']
75
+ end
76
+
77
+ def author
78
+ @pattern_author
79
+ end
80
+
81
+ def fave_colors
82
+ @data['fave_colors']
83
+ end
84
+
85
+ def fave_curse
86
+ @data['fave_curse']
87
+ end
88
+
89
+ def first_name
90
+ @data['first_name']
91
+ end
92
+
93
+ def large_photo_url
94
+ @data['large_photo_url']
95
+ end
96
+
97
+ def location
98
+ @data['location']
99
+ end
100
+
101
+ def photo_url
102
+ @data['photo_url']
103
+ end
104
+
105
+ def small_photo_url
106
+ @data['small_photo_url']
107
+ end
108
+
109
+ def tiny_photo_url
110
+ @data['tiny_photo_url']
111
+ end
112
+
113
+ def username
114
+ @data['username']
115
+ end
116
+
117
+ # ID from the Ravelry database.
118
+ #
119
+ def _id
120
+ @data['id']
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,22 @@
1
+ module Ravelry
2
+ # There is no API access point for UserSite. The information used to create `Ravelry::UserSite` comes from other objects.
3
+ #
4
+ # You should not create `UserSite` objects manually; they are all created–and owned by–other objects.
5
+ #
6
+ # This does not inherit from {Ravelry::Data} because it doesn't have a corresponding API endpoint.
7
+ #
8
+ class UserSite
9
+ attr_reader :id, :social_site, :url, :username
10
+
11
+ # Creates new `UserSite` from Ravelry API attributes.
12
+ #
13
+ # All class variables are readonly.
14
+ #
15
+ def initialize(user_site)
16
+ @id = user_site[:id]
17
+ @social_site = SocialSite.new(user_site[:social_site])
18
+ @url = user_site[:url]
19
+ @username = user_site[:username]
20
+ end
21
+ end
22
+ end
@@ -60,7 +60,7 @@ module Ravelry
60
60
  @packs
61
61
  end
62
62
 
63
- # Creates and returns a of {Ravelry::PatternType} object.
63
+ # Creates and returns a {Ravelry::PatternType} object.
64
64
  #
65
65
  # This is not the same as a PatternCategory object.
66
66
  #
@@ -96,6 +96,18 @@ module Ravelry
96
96
  @printings
97
97
  end
98
98
 
99
+ # Creates and returns an array of {Ravelry::UserSite} objects.
100
+ #
101
+ # See {Ravelry::UserSite} for more information.
102
+ #
103
+ def self.user_sites(data)
104
+ @user_sites = []
105
+ data[:user_sites].each do |site|
106
+ @user_sites << UserSite.new(site)
107
+ end
108
+ @user_sites
109
+ end
110
+
99
111
  # Creates and returns an array of {Ravelry::Yarn} objects.
100
112
  #
101
113
  # See {Ravelry::Yarn} for more information.
@@ -1,3 +1,3 @@
1
1
  module Ravelry
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,5 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Ravelry::User do
4
+ # todo!
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ravelry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liz Abinante
@@ -80,6 +80,9 @@ files:
80
80
  - lib/ravelry/pattern_type.rb
81
81
  - lib/ravelry/photo.rb
82
82
  - lib/ravelry/printing.rb
83
+ - lib/ravelry/social_site.rb
84
+ - lib/ravelry/user.rb
85
+ - lib/ravelry/user_site.rb
83
86
  - lib/ravelry/utils/build.rb
84
87
  - lib/ravelry/utils/utilities.rb
85
88
  - lib/ravelry/version.rb
@@ -101,6 +104,7 @@ files:
101
104
  - spec/ravelry/pattern_type_spec.rb
102
105
  - spec/ravelry/photo_spec.rb
103
106
  - spec/ravelry/printing_spec.rb
107
+ - spec/ravelry/user_spec.rb
104
108
  - spec/ravelry/utils/build_spec.rb
105
109
  - spec/ravelry/yarn_spec.rb
106
110
  - spec/ravelry/yarn_weight_spec.rb
@@ -146,6 +150,7 @@ test_files:
146
150
  - spec/ravelry/pattern_type_spec.rb
147
151
  - spec/ravelry/photo_spec.rb
148
152
  - spec/ravelry/printing_spec.rb
153
+ - spec/ravelry/user_spec.rb
149
154
  - spec/ravelry/utils/build_spec.rb
150
155
  - spec/ravelry/yarn_spec.rb
151
156
  - spec/ravelry/yarn_weight_spec.rb