Class: Sapphire

Inherits:
Object
  • Object
show all
Defined in:
lib/pure_sapphire.rb

Overview

Get the hottest posts from a subreddit

Defined Under Namespace

Classes: HTTPartyReddit, RestClientReddit

Class Method Summary collapse

Class Method Details

.consumer_fetchObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pure_sapphire.rb', line 29

def self.consumer_fetch
    if @client.nil?
        raise ArgumentError, "Client is not set, please call #pick_client first"
    end
    reddit_api = @client.new
    posts = reddit_api.get_posts(@subreddit)
    posts.each do |post|
        puts "Title: #{post[:title]}"
        puts "URL: #{post[:url]}"
        puts "-" * 50
    end  
end

.consumer_pick_client(client_name = "HTTParty", subreddit = "BeInspired") ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pure_sapphire.rb', line 15

def self.consumer_pick_client(client_name = "HTTParty", subreddit = "BeInspired")
  p "You choose " + client_name
  case client_name
  when "HTTParty"
    @client = HTTPartyReddit
  when "RestClient"
    @client = RestClientReddit
  else
    raise ArgumentError, "Invalid client: #{client_name} choose either HTTParty or RestClient"
  end
  @subreddit = subreddit

end

.gem_versionObject



7
8
9
# File 'lib/pure_sapphire.rb', line 7

def self.gem_version
  Gem::Version.new('1.0.1')
end

.summaryObject



11
12
13
# File 'lib/pure_sapphire.rb', line 11

def self.summary
  puts "I am a casual Reddit consumer"
end