Skip to content

Commit

Permalink
Merge pull request #2 from sue445/feture/character_api
Browse files Browse the repository at this point in the history
Impl character
  • Loading branch information
sue445 committed Mar 15, 2020
2 parents a240df5 + 960794f commit 454609e
Show file tree
Hide file tree
Showing 13 changed files with 520 additions and 10 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo_token: v7vHQpfptuMdfcdwWvbQ1JCAktHx8sJey
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ source "https://rubygems.org"
# Specify your gem's dependencies in prismdb.gemspec
gemspec

gem "coveralls"
gem "rake", "~> 12.0"
gem "rspec", "~> 3.0"
gem "rspec-its"
gem "simplecov"
gem "webmock", require: "webmock/rspec"
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Prismdb
[PrismDB](https://prismdb.takanakahiko.me/) API client for ruby

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/prismdb`. To experiment with that code, run `bin/console` for an interactive prompt.

TODO: Delete this and the text above, and describe your gem
[![test](https://github.com/sue445/prismdb-ruby/workflows/test/badge.svg?branch=master)](https://github.com/sue445/prismdb-ruby/actions?query=workflow%3Atest)
[![Coverage Status](https://coveralls.io/repos/github/sue445/prismdb-ruby/badge.svg?branch=master)](https://coveralls.io/github/sue445/prismdb-ruby?branch=master)
[![Maintainability](https://api.codeclimate.com/v1/badges/091d941f30ffc69fbd4b/maintainability)](https://codeclimate.com/github/sue445/prismdb-ruby/maintainability)

## Installation

Expand Down
12 changes: 11 additions & 1 deletion lib/prismdb.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
require "prismdb/version"
require "faraday"
require "faraday_middleware"

module Prismdb
autoload :Client, "prismdb/client"
autoload :Configuration, "prismdb/configuration"
autoload :Response, "prismdb/response"

class Error < StandardError; end
# Your code goes here...

# @return [Prismdb::Configuration]
def self.config
@config ||= Configuration.new
end
end
30 changes: 30 additions & 0 deletions lib/prismdb/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Prismdb
class Client
# @return [Array<Prismdb::Response>]
def characters
with_error_handling do
connection.get("/api/character").body["results"]
end
end

private

# @return [Faraday::Connection]
def connection
Faraday.new(url: Prismdb.config.api_endpoint) do |conn|
conn.request :json
conn.response :mashify, mash_class: Prismdb::Response
conn.response :json
conn.response :raise_error

conn.adapter Faraday.default_adapter
end
end

def with_error_handling
yield
rescue Faraday::ClientError, Faraday::ServerError => _error
raise Prismdb::Error
end
end
end
15 changes: 15 additions & 0 deletions lib/prismdb/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Prismdb
class Configuration
# @!attribute debug_logger
# @return [Logger]
attr_accessor :debug_logger

# @!attribute api_endpoint
# @return [String]
attr_accessor :api_endpoint

def initialize
@api_endpoint = "https://prismdb.takanakahiko.me"
end
end
end
7 changes: 7 additions & 0 deletions lib/prismdb/response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Prismdb
require "hashie/mash"

class Response < Hashie::Mash
disable_warnings
end
end
6 changes: 5 additions & 1 deletion prismdb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
spec.description = %q{PrismDB API client for ruby}
spec.homepage = "https://github.com/sue445/prismdb-ruby"
spec.license = "MIT"
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/sue445/prismdb-ruby"
Expand All @@ -24,4 +24,8 @@ 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", ">= 1.0.0"
spec.add_dependency "faraday_middleware"
spec.add_dependency "hashie"
end

0 comments on commit 454609e

Please sign in to comment.