Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
bezrukavyi committed Dec 12, 2017
0 parents commit 43af0c2
Show file tree
Hide file tree
Showing 24 changed files with 590 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status
vendor/bundle
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--format documentation
--color
--require spec_helper
49 changes: 49 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
AllCops:
Exclude:
- 'spec/**/*'
TargetRubyVersion: 2.4

Rails:
Enabled: true

HasAndBelongsToMany:
Enabled: false

Metrics/LineLength:
Max: 120

Metrics/AbcSize:
Enabled: false

Metrics/PerceivedComplexity:
Enabled: false

Metrics/ClassLength:
Enabled: false

Metrics/ModuleLength:
Enabled: false

Metrics/MethodLength:
Max: 35

Rails/TimeZone:
Enabled: false

Rails/Date:
Enabled: false

Metrics/CyclomaticComplexity:
Enabled: false

Documentation:
Enabled: false

ClassAndModuleChildren:
Enabled: false

FrozenStringLiteralComment:
Enabled: false

Performance/TimesMap:
Enabled: false
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.4.1
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sudo: false
language: ruby
rvm:
- 2.3.3
before_install: gem install bundler -v 1.16.0
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in api_struct.gemspec
gemspec
93 changes: 93 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
PATH
remote: .
specs:
api_struct (0.1.0)
dry-configurable (>= 0.7)
dry-monads (>= 0.3.1)
hashie (~> 3.5, >= 3.5.6)
http (>= 2.0.3)

GEM
remote: https://rubygems.org/
specs:
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.3.0)
byebug (9.1.0)
coderay (1.1.2)
concurrent-ruby (1.0.5)
diff-lcs (1.3)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
dry-configurable (0.7.0)
concurrent-ruby (~> 1.0)
dry-core (0.4.1)
concurrent-ruby (~> 1.0)
dry-equalizer (0.2.0)
dry-monads (0.4.0)
dry-core (~> 0.3, >= 0.3.3)
dry-equalizer
hashie (3.5.6)
http (3.0.0)
addressable (~> 2.3)
http-cookie (~> 1.0)
http-form_data (>= 2.0.0.pre.pre2, < 3)
http_parser.rb (~> 0.6.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
http-form_data (2.0.0)
http_parser.rb (0.6.0)
method_source (0.9.0)
parallel (1.12.0)
parser (2.4.0.2)
ast (~> 2.3)
powerpack (0.1.1)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.5.1)
byebug (~> 9.1)
pry (~> 0.10)
public_suffix (3.0.1)
rainbow (2.2.2)
rake
rake (12.3.0)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.0)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.0)
rubocop (0.50.0)
parallel (~> 1.10)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.4)
unicode-display_width (1.3.0)

PLATFORMS
ruby

DEPENDENCIES
api_struct!
bundler (~> 1.14)
pry-byebug
rake (~> 12.0)
rspec (>= 3.0)
rubocop (~> 0.50.0)

BUNDLED WITH
1.16.0
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 bezrukavyi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ApiStruct

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'api_struct'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install api_struct

## Usage

```ruby
API_ROOT = 'http://localhost:3000/api/v1'

# ApiStruct::Client.configure do
# setting :first_api, API_ROOT
# setting :second_api
# end

class NetworkClient < ApiStruct::Client
# first_api '/networks'
url API_ROOT + '/networks'

def show(network)
get(url + "/#{network}")
end

def index
get(url)
end
end

class User < ApiStruct::Entity
attr_entity :name, :id
end

class Network < ApiStruct::Entity
client_service NetworkClient

attr_entity :name, :id

has_entity :super_admin, as: User
end

network = Network.show('T7WU9CG65')
networks = Network.index
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/api_struct.

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
31 changes: 31 additions & 0 deletions api_struct.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'api_struct/version'

Gem::Specification.new do |spec|
spec.name = 'api_struct'
spec.version = ApiStruct::VERSION
spec.authors = ['bezrukavyi']
spec.email = ['[email protected]']

spec.summary = 'Api entities'
spec.description = 'Api entities'
spec.homepage = 'https://github.com/bezrukavyi'
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0")
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'dry-monads', '>= 0.3.1'
spec.add_dependency 'dry-configurable', '>= 0.7'
spec.add_dependency 'http', '>= 2.0.3'
spec.add_dependency 'hashie', '~> 3.5', '>= 3.5.6'

spec.add_development_dependency 'bundler', '~> 1.14'
spec.add_development_dependency 'pry-byebug'
spec.add_development_dependency 'rake', '~> 12.0'
spec.add_development_dependency 'rspec', '>= 3.0'
spec.add_development_dependency 'rubocop', '~> 0.50.0'
end
14 changes: 14 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "api_struct"

# 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.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require "irb"
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
18 changes: 18 additions & 0 deletions lib/api_struct.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'http'
require 'dry-monads'
require 'json'
require 'pry-byebug'
require 'hashie'

require_relative 'api_struct/version'
require_relative 'api_struct/extensions/api_client'
require_relative 'api_struct/extensions/dry_monads'
require_relative 'api_struct/extensions/json_api'
require_relative 'api_struct/errors/client'
require_relative 'api_struct/client'
require_relative 'api_struct/entity'
require_relative 'api_struct/errors/entity'

module ApiStruct

end
Loading

0 comments on commit 43af0c2

Please sign in to comment.