hermitcraft 0.1.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: 921019ba2a53bc41ad9ff57d8a1cf0523bbecf69
4
+ data.tar.gz: c4dda3e1b6dce631f530de45d4eed209663a0409
5
+ SHA512:
6
+ metadata.gz: 76c24845d3814da3ea5f81023e6086aa29178a6cdc2a3fcb2f4a7b9e05c534266ab5afe94127ae49521eaca30af1cee00dba7e83e225d0213986a96e1409e36a
7
+ data.tar.gz: f53bf3e8786c0ebecb665a8edc16dfe0f46510e438e7d8d9d5c5a1d4a91a2c48402fe4ebace51e8a3129007fbd6d9e3af3dcabe7a4d17cd80e0958ec4406cb49
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hermitcraft.gemspec
4
+ gemspec
@@ -0,0 +1,15 @@
1
+ The ISC License (ISC)
2
+
3
+ Copyright (c) Justin Kim
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,60 @@
1
+ # Hermitcraft - [hermitcraft.com][hermitcraft] interaction gem
2
+
3
+ [hermitcraft]: http://hermitcraft.com
4
+
5
+ [![Gem Version](http://img.shields.io/gem/v/hermitcraft.svg)][gem]
6
+ [![Build Status](http://img.shields.io/travis/justinkim/hermitcraft.svg)][travis]
7
+ [![Dependency Status](http://img.shields.io/gemnasium/justinkim/hermitcraft.svg)][gemnasium]
8
+ [![Coverage Status](https://img.shields.io/coveralls/justinkim/hermitcraft.svg)][coveralls]
9
+ [![Code Climate](http://img.shields.io/codeclimate/github/justinkim/hermitcraft.svg)][codeclimate]
10
+
11
+ [codeclimate]:https://codeclimate.com/github/justinkim/hermitcraft
12
+ [coveralls]: https://coveralls.io/r/justinkim/hermitcraft
13
+ [gem]: http://badge.fury.io/rb/hermitcraft
14
+ [gemnasium]: https://gemnasium.com/justinkim/hermitcraft
15
+ [travis]: https://travis-ci.org/justinkim/hermitcraft
16
+
17
+ GitHub: [https://github.com/justinkim/hermitcraft](http://github.com/justinkim/hermitcraft)
18
+
19
+ Documentation: [http://www.rubydoc.info/github/justinkim/hermitcraft](http://www.rubydoc.info/github/justinkim/hermitcraft)
20
+
21
+ Bugs: [https://github.com/justinkim/hermitcraft/issues](https://github.com/justinkim/hermitcraft/issues)
22
+
23
+ ## Description
24
+
25
+ This gem provides a wrapper for the Hermitcraft videos "API" located at [hermitcraft.com][hermitcraft]. With it, you can get the latest videos from all Hermits.
26
+
27
+ Yes, this gem is [semantically versioned](http://semver.org)!
28
+
29
+ ## Installation
30
+
31
+ Add this line to your application's Gemfile:
32
+
33
+ ```ruby
34
+ gem 'hermitcraft'
35
+ ```
36
+
37
+ And then execute:
38
+
39
+ $ bundle
40
+
41
+ Or install it yourself as:
42
+
43
+ $ gem install hermitcraft
44
+
45
+ ## Usage
46
+
47
+ TODO: Write usage instructions here
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/[my-github-username]/hermitcraft/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
56
+
57
+ ## License
58
+ Released under the ISC license. See the [LICENSE][] for further details.
59
+
60
+ [license]: LICENSE
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.test_files = Dir.glob('test/**/test_*.rb')
8
+ end
9
+
10
+ task(default: :test)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hermitcraft"
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,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hermitcraft/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'hermitcraft'
8
+ spec.version = Hermitcraft::VERSION
9
+ spec.authors = ['Justin Kim']
10
+ spec.email = ['yulli@yulli.org']
11
+
12
+ spec.summary = 'Interaction with the Hermitcraft videos API.'
13
+ spec.description = 'Use this gem to query the authoritative source of Hermitcraft videos.'
14
+ spec.homepage = 'https://github.com/justinkim/hermitcraft'
15
+ spec.license = 'ISC'
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.9'
23
+ spec.add_development_dependency 'minitest', '~> 5.7.0'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'vcr', '~> 2.9.3'
26
+ spec.add_development_dependency 'webmock', '~> 1.21.0'
27
+ end
@@ -0,0 +1,8 @@
1
+ require 'hermitcraft/api'
2
+ require 'hermitcraft/version'
3
+ require 'hermitcraft/video'
4
+ require 'hermitcraft/uploader'
5
+
6
+ module Hermitcraft
7
+ # Your code goes here...
8
+ end
@@ -0,0 +1,41 @@
1
+ require 'json'
2
+ require 'uri'
3
+ require 'time'
4
+
5
+ module Hermitcraft
6
+ # This class handles interaction with Hermitcraft.com's API, which is an open
7
+ # endpoint located at http://hermitcraft.com/api/videos. Hypno uses it in the
8
+ # site's Angular app to display videos on the main site.
9
+ class API
10
+ ENDPOINT = 'http://hermitcraft.com/api/videos'
11
+
12
+ # Fetches 25 videos in reverse chronological order from a point in time.
13
+ #
14
+ # @params time [Time] the point in time videos must be earlier than.
15
+ # Leave null for now.
16
+ # @return [Array] a bunch of Hermitcraft::Video objects.
17
+ def self.videos(time = nil)
18
+ time ||= Time.now.utc
19
+ time = time.iso8601
20
+ params = {type: 'All', start: time}
21
+
22
+ response = request(params)
23
+ process_response(response)
24
+ end
25
+
26
+ private
27
+
28
+ # Converts the JSON response into Video objects.
29
+ def self.process_response(videos)
30
+ videos.map! { |video| Video.new(video) }
31
+ end
32
+
33
+ # Submits a request to the API with the given params.
34
+ def self.request(params)
35
+ uri = URI(ENDPOINT)
36
+ uri.query = URI.encode_www_form(params)
37
+ response = Net::HTTP.get_response(uri).body
38
+ JSON.parse(response)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ module Hermitcraft
2
+ # This class wraps an uploader as represented by the Hermitcraft API.
3
+ class Uploader
4
+ attr_reader :id, :profile_picture, :display_name, :channel_name,
5
+ :google_plus_link, :twitter_name, :twitch_name, :website_url, :active,
6
+ :streaming, :channel_id, :upload_id
7
+
8
+ # Oddly enough, the API leaves some things as null values.
9
+ # id always seems to be 0, ChannelID and UploadID are always null
10
+ def initialize(attributes)
11
+ @id = attributes['id']
12
+ @profile_pictures = attributes['ProfilePicture']
13
+ @display_name = attributes['DisplayName']
14
+ @channel_name = attributes['ChannelName']
15
+ @google_plus_link = attributes['GooglePlusLink']
16
+ @twitter_name = attributes['TwitterName']
17
+ @twitch_name = attributes['TwitchName']
18
+ @website_url = attributes['WebsiteURL']
19
+ @active = attributes['Active']
20
+ @streaming = attributes['Streaming']
21
+ @channel_id = attributes['ChannelID']
22
+ @upload_id = attributes['UploadID']
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Hermitcraft
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,20 @@
1
+ require 'time'
2
+
3
+ module Hermitcraft
4
+ # This class wraps a video as represented by the Hermitcraft API.
5
+ class Video
6
+ attr_reader :id, :uploaded_at, :uploader, :title, :duration, :like_count,
7
+ :view_count, :comment_count
8
+
9
+ def initialize(attributes)
10
+ @id = attributes['id']
11
+ @uploaded_at = Time.parse(attributes['uploaded'])
12
+ @uploader = Uploader.new(attributes['uploader'])
13
+ @title = attributes['title']
14
+ @duration = attributes['duration']
15
+ @like_count = attributes['likeCount'].to_i # hypno wat
16
+ @view_count = attributes['viewCount']
17
+ @comment_count = attributes['commentCount']
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hermitcraft
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Kim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-16 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 5.7.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 5.7.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.9.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.9.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.21.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.21.0
83
+ description: Use this gem to query the authoritative source of Hermitcraft videos.
84
+ email:
85
+ - yulli@yulli.org
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - hermitcraft.gemspec
99
+ - lib/hermitcraft.rb
100
+ - lib/hermitcraft/api.rb
101
+ - lib/hermitcraft/uploader.rb
102
+ - lib/hermitcraft/version.rb
103
+ - lib/hermitcraft/video.rb
104
+ homepage: https://github.com/justinkim/hermitcraft
105
+ licenses:
106
+ - ISC
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.5
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Interaction with the Hermitcraft videos API.
128
+ test_files: []