chaos-api 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 956d0eb72667b7eb78cff258d6b305b526a7de1b
4
+ data.tar.gz: f205ea5055d9bc12b65213b8e7bd804737b66106
5
+ SHA512:
6
+ metadata.gz: 30e8fcf90708857ea299a38f3fcc486c5f3c02c5038adc597e13a8b79e6638c9965af32092508fd0312fe51a8295e02a4955c3b96b6e59033d1c80e5e8968783
7
+ data.tar.gz: 3f81cbc1b39a96b4c53e53e04c0b6610e23dc216d683d3ef18431236aea120b24756d4ba9865f0a98695e3a495e7d3dd716f04870c49df51b6344f8607580ffe
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chaos_api.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Chaos::API
2
+
3
+ Simple interface to leftBehind game
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'chaos-api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install chaos-api
20
+
21
+ ## Usage
22
+
23
+ By now, you should know how to use yhis, if not, that's not for u :)
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/chapuzzo/chaos-api.
34
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "chaos_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/chaos-api.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chaos/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chaos-api"
8
+ spec.version = Chaos::API::VERSION
9
+ spec.authors = ["chapuzzo"]
10
+ spec.email = ["luismax@gmail.com"]
11
+
12
+ spec.summary = %q{API interface to leftBehind game}
13
+ spec.description = %q{API interface to leftBehind game}
14
+ spec.homepage = "https://chaosgame.herokuapp.com"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{(^(test|spec|features)/|\.rspec)}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency 'awesome_print'
30
+ spec.add_dependency 'faraday'
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.12"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ end
@@ -0,0 +1,5 @@
1
+ module Chaos
2
+ class API
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
data/lib/chaos/api.rb ADDED
@@ -0,0 +1,101 @@
1
+ require "chaos/api/version"
2
+
3
+ require 'faraday'
4
+ require 'awesome_print'
5
+
6
+ module Chaos
7
+ class API
8
+
9
+ URLS = {
10
+ local: 'http://localhost:3000',
11
+ staging: 'http://chaosgame.herokuapp.com'
12
+ }
13
+
14
+ ACTIONS = {
15
+ get_available_games: {
16
+ route: '/games/available'
17
+ },
18
+ create_game: {
19
+ route: '/games/create'
20
+ },
21
+ game_ready: {
22
+ route: '/games/ready'
23
+ },
24
+ join_game: {
25
+ route: '/games/join'
26
+ },
27
+ get_stats: {
28
+ route: '/games/get-stats'
29
+ },
30
+ send_actions: {
31
+ route: '/actions/send-selected'
32
+ },
33
+ get_game_locations: {
34
+ route: '/games/locations'
35
+ },
36
+ team_mates:{
37
+ route: '/games/team-mates'
38
+ },
39
+ start_game: {
40
+ route: '/games/start'
41
+ }
42
+ }
43
+
44
+ def initialize env = :local
45
+ env = URLS[env.to_sym] if URLS.keys.include? env.to_sym
46
+
47
+ @connection = Faraday.new(
48
+ url: env,
49
+ ssl: {
50
+ ca_path: '/usr/lib/ssl/certs',
51
+ verify: false
52
+ }
53
+ )
54
+ end
55
+
56
+ def call command, params = {}, as_json = false
57
+ method = ACTIONS[command][:verb] || :post
58
+ route = ACTIONS[command][:route]
59
+
60
+ response = @connection.send(method, route, params)
61
+ return JSON(response.body) if as_json
62
+ response
63
+ end
64
+
65
+ def debug command, params = {}, as_json = false
66
+ response = call(command, params, as_json)
67
+
68
+ if as_json
69
+ ap response
70
+ return response
71
+ end
72
+
73
+ ap response.status
74
+ parsed = (JSON.parse(response.body) rescue response.body)
75
+ ap parsed
76
+ response
77
+ end
78
+
79
+ # def authenticate token
80
+ # @connection.headers['Authorization'] = "Bearer #{token}"
81
+ # end
82
+
83
+ # def login params
84
+ # response = debug :login, params: params
85
+ # return false unless response.status == 200
86
+
87
+ # token = JSON.parse(response.body)['access_token']
88
+ # authenticate token
89
+ # end
90
+
91
+
92
+ ACTIONS.keys.each do |command|
93
+ ap command
94
+ define_method(command) { |params = {}, as_json = false|
95
+ ap params
96
+ debug command, params, as_json
97
+ }
98
+ end
99
+ end
100
+ end
101
+
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chaos-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - chapuzzo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: awesome_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: API interface to leftBehind game
84
+ email:
85
+ - luismax@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - chaos-api.gemspec
98
+ - lib/chaos/api.rb
99
+ - lib/chaos/api/version.rb
100
+ homepage: https://chaosgame.herokuapp.com
101
+ licenses: []
102
+ metadata:
103
+ allowed_push_host: https://rubygems.org
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.6
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: API interface to leftBehind game
124
+ test_files: []