Class: Hyperscore::Client

Inherits:
Object
  • Object
show all
Includes:
Hyperclient
Defined in:
lib/hyperscore/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(url = 'http://cs-api.herokuapp.com/') ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
# File 'lib/hyperscore/client.rb', line 10

def initialize(url='http://cs-api.herokuapp.com/')
  @client = Hyperclient::EntryPoint.new url, {
    headers: { 'Accept-Encoding' => 'gzip,deflate' }
  }
end

Instance Method Details

#dashboard(username) ⇒ Object



43
44
45
# File 'lib/hyperscore/client.rb', line 43

def dashboard(username)
  get_user(username).links.dashboard.url
end

#gamesObject



29
30
31
# File 'lib/hyperscore/client.rb', line 29

def games
  @client.links.games.embedded.games
end

#motdObject



47
48
49
# File 'lib/hyperscore/client.rb', line 47

def motd
  @client.attributes['motd']
end

#newsObject



16
17
18
19
20
21
22
23
# File 'lib/hyperscore/client.rb', line 16

def news
  @client.links.news.embedded.news.map do |news|
    Hyperscore::Coercions::News.new( news.get.merge({
      :source => news.links.self.url,
      :site   => news.links.alternate.url
    }) )
  end
end

#profile(username) ⇒ Object



39
40
41
# File 'lib/hyperscore/client.rb', line 39

def profile(username)
  get_user(username).links.profile.url
end

#submissionsObject



25
26
27
# File 'lib/hyperscore/client.rb', line 25

def submissions
  @client.links.submissions.embedded.submissions
end

#user(username) ⇒ Object



33
34
35
36
37
# File 'lib/hyperscore/client.rb', line 33

def user(username)
  user = @client.links.users.links.search.expand({username: username}).get

  user.key?('error') ? nil : user
end