Class: XkcdGuru::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/xkcd-gem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Client

XkcdGuru::Client.new(‘localhost:3000’) XkcdGuru::Client.new(‘xkcd-unofficial-api.herokuapp.com/xkcd’)



9
10
11
# File 'lib/xkcd-gem.rb', line 9

def initialize(url)
  @url = url
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/xkcd-gem.rb', line 5

def url
  @url
end

Instance Method Details

#comic_by_alt(alt) ⇒ Object



44
45
46
# File 'lib/xkcd-gem.rb', line 44

def comic_by_alt(alt)
 return HTTParty.get("#{@url}?alt=#{alt}")
end

#comic_by_date(year, month = nil, day = nil) ⇒ Object

response = HTTParty.get(‘xkcd-unofficial-api.herokuapp.com/xkcd?year=2007’) this gets comics 1-60 all_comics = {}; for num in 0..60

all_comics[num] = HTTParty.get("http://xkcd.com/#{num}/info.0.json")

end



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/xkcd-gem.rb', line 19

def comic_by_date(year, month = nil, day = nil)
    if day
      day_text = "&day=#{day}"
    end
    if month
      month_text = "&month=#{month}"
   #{month_text}#{day_text}")
  end

  def comic_by_month(month, day = nil)
   return HTTParty.get("#{@url}?month=#{month}")
  end

  def comic_by_day(day)
   return HTTParty.get("#{@url}?day=#{day}")
  end

  def comic_by_num(num)
   return HTTParty.get("#{@url}?num=#{num}")
  end

  def comic_by_title(safe_title)
   return HTTParty.get("#{@url}?safe_title=#{safe_title}")
  end

  def comic_by_alt(alt)
   return HTTParty.get("#{@url}?alt=#{alt}")
  end
end

#comic_by_day(day) ⇒ Object



32
33
34
# File 'lib/xkcd-gem.rb', line 32

def comic_by_day(day)
 return HTTParty.get("#{@url}?day=#{day}")
end

#comic_by_month(month, day = nil) ⇒ Object



28
29
30
# File 'lib/xkcd-gem.rb', line 28

def comic_by_month(month, day = nil)
 return HTTParty.get("#{@url}?month=#{month}")
end

#comic_by_num(num) ⇒ Object



36
37
38
# File 'lib/xkcd-gem.rb', line 36

def comic_by_num(num)
 return HTTParty.get("#{@url}?num=#{num}")
end

#comic_by_title(safe_title) ⇒ Object



40
41
42
# File 'lib/xkcd-gem.rb', line 40

def comic_by_title(safe_title)
 return HTTParty.get("#{@url}?safe_title=#{safe_title}")
end