japi 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aef6040b8f468c6963822eb2313e611f54021e11
4
+ data.tar.gz: b1e032b9e2b438ef60d125b05a7ab0582e60ced0
5
+ SHA512:
6
+ metadata.gz: 11e59b930bef6c06675d67cb188131884b32134cb26d0d373b3c37124e9df25ecffdce7a4d25b487d3f4b9943a169b37680dcc1e1634615cac3425dce2a91465
7
+ data.tar.gz: df01c55d167e0d6ef303fb44478aa13e862482197a74e0d34a1bd3804752e50bd5c3d40884f60e6052b8d441547d1a5165b79d4317f3a2fd27218a44d9df3540
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.swp
11
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ - 2.1.1
5
+ - 1.9.3
6
+
7
+ before_install: gem install bundler -v 1.10.6
8
+ script: bundle exec rake test
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Dean Silfen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # JAPI
2
+
3
+ ![build status](https://travis-ci.org/djds23/jApi.svg?branch=master)
4
+
5
+ A simple ruby interface for the jservice.io API
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'japi'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install japi
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ clue = JAPI::Trebek.random # ask trebek for a random question!
27
+ puts clue.category.title # THE SOLAR SYSTEM
28
+ puts clue.question # Only 1 of 9 planets not named for a Greek or Roman mythological figure
29
+
30
+ answer = gets.chomp
31
+ if answer == clue.answer
32
+ puts "The Earth! Correct!"
33
+ puts "Good answer! Thats worth #{clue.value} dollars!"
34
+ else
35
+ puts "Too bad!"
36
+ end
37
+ ```
38
+ ## Development
39
+
40
+ 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.
41
+
42
+ 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).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/djds23/japi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
47
+
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
52
+
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "japi"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'japi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "japi"
8
+ spec.version = JAPI::VERSION
9
+ spec.authors = ["Dean Silfen"]
10
+ spec.email = ["dean.silfen@gmail.com"]
11
+
12
+ spec.summary = %q{A simple object wrapper for the jservice.io API.}
13
+ spec.description = %q{A simple object wrapper for the jservice.io API.}
14
+ spec.homepage = "http://btrebek.com/"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "yard"
26
+ end
@@ -0,0 +1,14 @@
1
+ require "japi/version"
2
+ require "japi/trebek"
3
+ require "japi/category"
4
+ require "japi/clue"
5
+
6
+
7
+ module JAPI
8
+ require "open-uri"
9
+ require 'json'
10
+ require 'uri'
11
+
12
+ class InvalidParamError < StandardError; end
13
+ end
14
+
@@ -0,0 +1,29 @@
1
+ module JAPI
2
+ class Category
3
+
4
+ def initialize(options = {})
5
+ @options = options
6
+ if @options["clues"]
7
+ @options["clues"] = @options["clues"].map { |clue| Clue.new(clue) }
8
+ end
9
+ end
10
+
11
+ def title
12
+ @options["title"]
13
+ end
14
+
15
+ def category_id
16
+ @options["id"]
17
+ end
18
+
19
+ def clues_count
20
+ @options["clues_count"]
21
+ end
22
+
23
+ def clues
24
+ return @options["clues"] unless @options["clues"].nil?
25
+ @options["clues"] = Trebek.category(10044).clues
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,33 @@
1
+ module JAPI
2
+ class Clue
3
+
4
+ def initialize(options = {})
5
+ @options = options
6
+ end
7
+
8
+ def value
9
+ @options["value"]
10
+ end
11
+
12
+ def clue_id
13
+ @options["id"]
14
+ end
15
+
16
+ def category_id
17
+ @options["category_id"]
18
+ end
19
+
20
+ def game_id
21
+ @options["game_id"]
22
+ end
23
+
24
+ def question
25
+ @options["question"]
26
+ end
27
+
28
+ def answer
29
+ @options["answer"]
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,86 @@
1
+ module JAPI
2
+ class Trebek
3
+ class << self
4
+
5
+ # Get a random clue from the service
6
+ #
7
+ # @param count [Fixnum] amount of clues to return, limited to 100 at a time
8
+ #
9
+ # @return [Array<Clue>] A list of random clues
10
+ def random(count = 1)
11
+ url = base_url << "random/?" << URI.encode_www_form({count: count})
12
+ response = JSON.parse(open(url).read)
13
+
14
+ response.map do |clue|
15
+ Clue.new(clue)
16
+ end
17
+ end
18
+
19
+ # Get a list of clues from the service
20
+ #
21
+ # @param options [Hash{String, Symbol => Fixnum, DateTime}] hash of query params for clue endpoint
22
+ # @option options [Fixnum] :value the value of the clue in dollars
23
+ # @option options [Fixnum] :category the id of the category you want to return
24
+ # @option options [DateTime] :min_date earliest date to show, based on original air date
25
+ # @option options [DateTime] :max_date latest date to show, based on original air date
26
+ # @option options [Fixnum] :offset offsets the returned clues. Useful in pagination
27
+ #
28
+ # @return [Array<Clue>] A list of clues that fit the query params
29
+ def clues(options = {})
30
+ allowed_keys = ['value', 'category', 'max_date', 'min_date', 'offset']
31
+ options.keys.each do |key|
32
+ unless allowed_keys.include?(key.to_s)
33
+ message = "#{key} is not allowed, please only use the following options: #{allowed_keys.join(', ')}"
34
+ raise InvalidParamError.new(message)
35
+ end
36
+ end
37
+ query = URI.encode_www_form(options)
38
+ response = JSON.parse(open(base_url << 'clues/?' << query).read)
39
+
40
+ response.map do |clue|
41
+ Clue.new(clue)
42
+ end
43
+ end
44
+
45
+ # Get a list of categories from the service
46
+ #
47
+ # @param options [Hash{String, Symbol => Fixnum}] hash of query params for clue endpoint
48
+ # @option options [Fixnum] :count amount of categories to return, limited to 100 at a time
49
+ # @option options [Fixnum] :offset offsets the starting id of categories returned. Useful in pagination.
50
+ #
51
+ # @return [Array<Category>] A list of clues that fit the query params
52
+ def categories(options = {})
53
+ allowed_keys = ['count', 'offset']
54
+ options.keys.each do |key|
55
+ unless allowed_keys.include?(key.to_s)
56
+ message = "#{key} is not allowed, please only use the following options: #{allowed_keys.join(', ')}"
57
+ raise InvalidParamError.new(message)
58
+ end
59
+ end
60
+ query = URI.encode_www_form(options)
61
+ response = JSON.parse(open(base_url << 'categories/?' << query).read)
62
+
63
+ response.map do |category|
64
+ Category.new(category)
65
+ end
66
+ end
67
+
68
+ # Get clues of a single category from the service
69
+ #
70
+ # @param id [Fixnum] id of desired category
71
+ #
72
+ # @return [Category] A list of clues that fit the query params
73
+ def category(id)
74
+ query = URI.encode_www_form(id: id)
75
+ response = JSON.parse(open(base_url << 'category/?' << query).read)
76
+ Category.new(response)
77
+ end
78
+
79
+ private
80
+ def base_url
81
+ "http://jservice.io/api/"
82
+ end
83
+ end
84
+ end
85
+ end
86
+
@@ -0,0 +1,3 @@
1
+ module JAPI
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: japi
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dean Silfen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A simple object wrapper for the jservice.io API.
70
+ email:
71
+ - dean.silfen@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - japi.gemspec
87
+ - lib/japi.rb
88
+ - lib/japi/category.rb
89
+ - lib/japi/clue.rb
90
+ - lib/japi/trebek.rb
91
+ - lib/japi/version.rb
92
+ homepage: http://btrebek.com/
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.8
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A simple object wrapper for the jservice.io API.
116
+ test_files: []
117
+ has_rdoc: