Module: GrepPage::API

Defined in:
lib/grepg/api.rb

Constant Summary collapse

BASE_URL =
'https://www.greppage.com/api'
ACCESS_TOKEN =
'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImFsZyI6IkhTMjU2IiwidHlwIjoiSldUIn0.eyJpZCI6MjAwMDAwMDAwMCwiZW1haWwiOiJndWVzdEBndWVzdC5jb20iLCJuYW1lIjoiZ3Vlc3QiLCJleHAiOjE1MTExMzY4MzB9.gWohR7LLtROgjSl5SxbEaGRBveZQEv7Uj2rzmgYrbys'

Class Method Summary collapse

Class Method Details

.cheats(user_name, sheet_id) ⇒ Object

Raises:

  • (Exception)


18
19
20
21
22
23
# File 'lib/grepg/api.rb', line 18

def self.cheats(user_name, sheet_id)
  response = get(cheats_uri(user_name, sheet_id))
  raise Exception if response.code != 200

  JSON.parse(response.to_str, symbolize_names: true)
end

.cheats_uri(user_name, sheet_id) ⇒ Object



29
30
31
# File 'lib/grepg/api.rb', line 29

def self.cheats_uri(user_name, sheet_id)
  [BASE_URL, 'users', user_name, 'sheets', sheet_id, 'cheats'].join('/')
end

.get(uri, access_token = ACCESS_TOKEN) ⇒ Object



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

def self.get(uri, access_token = ACCESS_TOKEN)
  RestClient.get uri, {:accept => :json, :authorization => access_token}
end

.sheets(user_name) ⇒ Object

Raises:

  • (RunTimeException)


11
12
13
14
15
16
# File 'lib/grepg/api.rb', line 11

def self.sheets(user_name)
  response = get(sheets_uri(user_name))
  raise RunTimeException if response.code != 200

  JSON.parse(response.to_str, symbolize_names: true)
end

.sheets_uri(user_name) ⇒ Object



25
26
27
# File 'lib/grepg/api.rb', line 25

def self.sheets_uri(user_name)
  [BASE_URL, 'users', user_name, 'sheets_with_stats'].join('/')
end