Module: Hackpad::Cli::Api
- Defined in:
- lib/hackpad/cli/api.rb
Class Method Summary collapse
- .get(url, json = true) ⇒ Object
- .list ⇒ Object
- .prepare(config) ⇒ Object
- .read(id, ext) ⇒ Object
- .read_options(id) ⇒ Object
- .search(term, start = 0) ⇒ Object
Class Method Details
.get(url, json = true) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/hackpad/cli/api.rb', line 39 def get(url, json = true) res = @token.get url, 'User-Agent' => "hackpad-cli v#{Hackpad::Cli::VERSION}" if res.is_a? Net::HTTPSuccess json ? JSON.parse(res.body) : res.body else fail ApiException, "HTTP error, code #{res.code}" end end |
.list ⇒ Object
27 28 29 |
# File 'lib/hackpad/cli/api.rb', line 27 def list get '/api/1.0/pads/all' end |
.prepare(config) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/hackpad/cli/api.rb', line 14 def prepare(config) consumer = OAuth::Consumer.new( config.client_id, config.secret, site: config.site ) @token = OAuth::AccessToken.new consumer end |
.read(id, ext) ⇒ Object
35 36 37 |
# File 'lib/hackpad/cli/api.rb', line 35 def read(id, ext) get "/api/1.0/pad/#{id}/content.#{ext}", false end |
.read_options(id) ⇒ Object
31 32 33 |
# File 'lib/hackpad/cli/api.rb', line 31 def (id) get "/api/1.0/pad/#{id}/options" end |
.search(term, start = 0) ⇒ Object
23 24 25 |
# File 'lib/hackpad/cli/api.rb', line 23 def search(term, start = 0) get "/api/1.0/search?q=#{CGI.escape term}&start=#{start}&limit=100" end |