Sha256: 84318c27263ed4c6e4f27291c94e026a85b28030bc8f996651c36502366f8f98

Contents?: true

Size: 1.11 KB

Versions: 8

Compression:

Stored size: 1.11 KB

Contents

require 'rest-client'

module GrepPage
  module API
    BASE_URL = 'https://www.greppage.com/api'
    ACCESS_TOKEN = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImFsZyI6IkhTMjU2IiwidHlwIjoiSldUIn0.eyJpZCI6MjAwMDAwMDAwMCwiZW1haWwiOiJndWVzdEBndWVzdC5jb20iLCJuYW1lIjoiZ3Vlc3QiLCJleHAiOjE1MTExMzY4MzB9.gWohR7LLtROgjSl5SxbEaGRBveZQEv7Uj2rzmgYrbys'
    def self.get(uri, access_token = ACCESS_TOKEN)
      RestClient.get uri, {:accept => :json, :authorization => access_token}
    end

    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

    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

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
grepg-0.0.9 lib/grepg/api.rb
grepg-0.0.8 lib/grepg/api.rb
grepg-0.0.7 lib/grepg/api.rb
grepg-0.0.6 lib/grepg/api.rb
grepg-0.0.5 lib/grepg/api.rb
grepg-0.0.4 lib/grepg/api.rb
grepg-0.0.3 lib/grepg/api.rb
grepg-0.0.2 lib/grepg/api.rb