class Ravelry::User

`Ravelry::User` corresponds to User objects in Ravelry and the `People#show` endpoint.

This class requires your environment variables be set (see {file:README.md README}). API calls are authenticated using HTTP Basic Auth unless otherwise noted.

#User objects

To create an empty object:

“`ruby user = Ravelry::User.new “`

To complete the `GET` request, set the `id` (this is the desired user's username) and run:

“`ruby user.id = “feministy” user.get “`

After calling `get`, you have access to all of the class methods below.

##Initializing with an id

Optionally, you can initialize with an id:

“`ruby user = Ravelry::User.new(id) “`

And then run your get request:

“`ruby user.get “`

Upon completing the `get` request, all of your objects and methods will ready to use!

##Loading existing user data

If you have existing user data, you should initialize as follows:

“`ruby user = Ravelry::User.new user.data = my_data “`

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.

This will create the following objects and readers from the existing `data`:

See the documentation for each object's available methods.

Attributes

pattern_author[R]
user_sites[R]

Public Instance Methods

_id() click to toggle source

ID from the Ravelry database.

# File lib/ravelry/user.rb, line 119
def _id
  @data[:id]
end
about_me() click to toggle source
# File lib/ravelry/user.rb, line 69
def about_me
  @data[:about_me]
end
about_me_html() click to toggle source
# File lib/ravelry/user.rb, line 73
def about_me_html
  @data[:about_me_html]
end
author() click to toggle source
# File lib/ravelry/user.rb, line 77
def author
  @pattern_author
end
fave_colors() click to toggle source
# File lib/ravelry/user.rb, line 81
def fave_colors
  @data[:fave_colors]
end
fave_curse() click to toggle source
# File lib/ravelry/user.rb, line 85
def fave_curse
  @data[:fave_curse]
end
first_name() click to toggle source
# File lib/ravelry/user.rb, line 89
def first_name
  @data[:first_name]
end
get() click to toggle source
# File lib/ravelry/user.rb, line 60
def get
  request = Typhoeus::Request.get("https://api.ravelry.com/people/#{@id}.json", userpwd: "#{Ravelry.configuration.access_key}:#{Ravelry.configuration.personal_key}")
  result = JSON.parse(request.response_body, {symbolize_names: true})
  @data = result[:user]
  @pattern_author = Build.author(@data)
  @user_sites = Build.user_sites(@data)
  self
end
large_photo_url() click to toggle source
# File lib/ravelry/user.rb, line 93
def large_photo_url
  @data[:large_photo_url]
end
location() click to toggle source
# File lib/ravelry/user.rb, line 97
def location
  @data[:location]
end
photo_url() click to toggle source
# File lib/ravelry/user.rb, line 101
def photo_url
  @data[:photo_url]
end
small_photo_url() click to toggle source
# File lib/ravelry/user.rb, line 105
def small_photo_url
  @data[:small_photo_url]
end
tiny_photo_url() click to toggle source
# File lib/ravelry/user.rb, line 109
def tiny_photo_url
  @data[:tiny_photo_url]
end
username() click to toggle source
# File lib/ravelry/user.rb, line 113
def username
  @data[:username]
end

Private Instance Methods

build() click to toggle source
# File lib/ravelry/user.rb, line 124
def build
  @id = @data[:id] unless @id
end