Skip to content

Commit

Permalink
Add basic api
Browse files Browse the repository at this point in the history
  • Loading branch information
geeknees committed Jul 4, 2020
1 parent 8cd974b commit 7b11e95
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ PATH
remote: .
specs:
redash_rb (0.1.0)
faraday

GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.4.4)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
multipart-post (2.1.1)
rake (12.3.3)
rspec (3.9.0)
rspec-core (~> 3.9.0)
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,23 @@ Or install it yourself as:

## Usage

TODO: Write usage instructions here
#### Configure

```ruby
require 'redash_rb'

Redash.configure do | config |
config.host = 'https://app.redash.io/<slug>'
config.api_token = '<api_token>'
end
```

#### API call

```ruby
client = Redash.client
client.get('/<slug>/api/queries')
```

## Development

Expand Down
7 changes: 4 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "redash_rb"
require 'bundler/setup'
require 'redash'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -10,5 +11,5 @@ require "redash_rb"
# require "pry"
# Pry.start

require "irb"
require 'irb'
IRB.start(__FILE__)
26 changes: 26 additions & 0 deletions lib/redash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require 'redash/client'
require 'redash/configuration'

module Redash
module ClassMethods
def client
@client ||= Client.new(config)
end

def client=(new_client)
@client = new_client
end

def config
@config ||= Configuration.new
end

def configure
yield config
end
end

extend ClassMethods
end
30 changes: 30 additions & 0 deletions lib/redash/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require 'faraday'

module Redash
class Client
attr_reader :config

def initialize(config)
@config = config
end

def get(uri, params = {})
connection.get(uri, params)
end

def connection
@connection ||= build_connection
end

private

def build_connection
Faraday.new(url: config.host) do |builder|
builder.authorization('Key', config.api_token) if config.api_token
builder.adapter Faraday.default_adapter
end
end
end
end
10 changes: 10 additions & 0 deletions lib/redash/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require 'faraday'

module Redash
class Configuration
attr_accessor :host
attr_accessor :api_token
end
end
5 changes: 5 additions & 0 deletions lib/redash/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module Redash
VERSION = '0.1.0'
end
9 changes: 0 additions & 9 deletions lib/redash_rb.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/redash_rb/version.rb

This file was deleted.

5 changes: 3 additions & 2 deletions redash_rb.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require_relative 'lib/redash_rb/version'
require_relative 'lib/redash/version'

Gem::Specification.new do |spec|
spec.name = "redash_rb"
spec.version = RedashRb::VERSION
spec.version = Redash::VERSION
spec.authors = ["Masumi Kawasaki"]
spec.email = ["[email protected]"]

Expand All @@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_dependency 'faraday'
end

0 comments on commit 7b11e95

Please sign in to comment.