-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sue445/feture/character_api
Impl character
- Loading branch information
Showing
13 changed files
with
520 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
repo_token: v7vHQpfptuMdfcdwWvbQ1JCAktHx8sJey |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.