whenhub 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: c0f343e2acd32d7e7eb9f0a38786ad1cc58f5c80
4
+ data.tar.gz: f56a305ec39851f53e67125d04f44c0c3cef0493
5
+ SHA512:
6
+ metadata.gz: cf12852146574cb66eb29e4817a0538aadd6a296b5e23541aced46d13b7770697b03a1b88b49175210311c59dbf194542d5fa8a31c11c5949e8e0d83c8906274
7
+ data.tar.gz: 4deb730636fa9967524a2c75ebd155b310cba9111043472d3b0e7c20f17f21b463c231ea4da0b4ebc31f7ffc7fb356a442c466e5aec06bd8161026cd28f65b32
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in whenhub.gemspec
4
+ gemspec
@@ -0,0 +1,122 @@
1
+ # WhenHub
2
+
3
+ This is a gem for interacting with [the WhenHub API](https://developer.whenhub.com/).
4
+
5
+ > WhenHub lets you transform time-ordered information such as a timeline or schedule into a beautiful, interactive, embeddable Whencast that entertains, educates, and provides chronological context.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'whenhub'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install whenhub
23
+
24
+ ## Usage
25
+
26
+ The best guide for using this gem is the script in `bin/test`, which exercises all of the supported endpoints and prints the method outputs.
27
+ You can use this script as a guide for invoking the gem, and you can run it against your live WhenHub account by running:
28
+
29
+ ```
30
+ RESTCLIENT_LOG=stdout bundle exec bin/test [YOUR ACCESS TOKEN]
31
+ ```
32
+
33
+ The gem uses a client model to query against the API. You create and configure a client with your access token.
34
+ (Note: You can find your access token by visiting your [WhenHub account page](https://studio.whenhub.com/account).)
35
+
36
+ ```
37
+ require 'whenhub'
38
+
39
+ client = WhenHub::Client.new(access_token: YOUR_ACCESS_TOKEN)
40
+ ```
41
+
42
+ After creating the client you're able to make requests to any of the WhenHub APIs.
43
+ Some examples follow below.
44
+
45
+ ### [My User Information](https://developer.whenhub.com/v1.0/reference#users-me)
46
+
47
+ ```
48
+ user = client.me
49
+ ```
50
+
51
+ ### [My Schedules](https://developer.whenhub.com/v1.0/reference#usersmeschedules)
52
+
53
+ ```
54
+ schedules = client.schedules.all
55
+ ```
56
+
57
+ ### [Schedule with Events](https://developer.whenhub.com/v1.0/reference#usersmeschedulesscheduleidfilterincludeevents)
58
+
59
+ ```
60
+ schedule = client.schedules.find(schedule_id)
61
+ ```
62
+
63
+ ### [Schedules with Events & Media](https://developer.whenhub.com/v1.0/reference#schedule-with-events-and-media)
64
+
65
+ ```
66
+ schedule = client.schedules.find(schedule_id, media: true)
67
+ ```
68
+
69
+ ### [Create a new schedule](https://developer.whenhub.com/v1.0/reference#create-a-new-schedule)
70
+
71
+ ```
72
+ schedule = client.schedules.create
73
+ ```
74
+
75
+ ### [Create a new event](https://developer.whenhub.com/v1.0/reference#create-a-new-event)
76
+
77
+ ```
78
+ event = schedule.events.create
79
+ ```
80
+
81
+ ### [Update an event](https://developer.whenhub.com/v1.0/reference#update-an-event)
82
+
83
+ ```
84
+ event.name = 'My Event'
85
+ event.save
86
+ ```
87
+
88
+ ### [Remove an event](https://developer.whenhub.com/v1.0/reference#remove-an-event)
89
+
90
+ ```
91
+ event.delete
92
+ ```
93
+
94
+ ### [Delete Multiple Events](https://developer.whenhub.com/v1.0/reference#delete-multiple-events)
95
+
96
+ ```
97
+ schedule.events.delete(event_ids)
98
+ ```
99
+
100
+ ### [Add an image to a Schedule](https://developer.whenhub.com/v1.0/reference#add-an-image-to-a-schedule)
101
+
102
+ ```
103
+ schedule.upload_image(url)
104
+ ```
105
+
106
+ ### [Add an image to an Event](https://developer.whenhub.com/v1.0/reference#add-an-image-to-an-event)
107
+
108
+ ```
109
+ event.upload_image(url)
110
+ ```
111
+
112
+
113
+ ## Development
114
+
115
+ 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.
116
+
117
+ 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).
118
+
119
+ ## Contributing
120
+
121
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/whenhub.
122
+
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "whenhub"
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(__FILE__)
@@ -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
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'whenhub'
4
+
5
+ client = WhenHub.client(access_token: ARGV.last)
6
+
7
+ puts 'client.me'
8
+ p client.me
9
+ puts
10
+ puts '------------'
11
+ puts
12
+
13
+ puts 'client.schedules.all'
14
+ schedules = client.schedules.all
15
+ p schedules
16
+ puts
17
+ puts '------------'
18
+ puts
19
+
20
+ puts 'client.schedules.find(schedule_id)'
21
+ schedule_id = schedules.first.id
22
+ schedule = client.schedules.find(schedule_id)
23
+ p schedule
24
+ puts
25
+ puts '------------'
26
+ puts
27
+
28
+ puts 'client.schedules.find(schedule_id, media: true)'
29
+ schedule = client.schedules.find(schedule_id, media: true)
30
+ p schedule
31
+ puts
32
+ puts '------------'
33
+ puts
34
+
35
+ schedule = client.schedules.create(
36
+ name: 'Hello World',
37
+ description: 'Here is a test schedule I am trying to create',
38
+ scope: 'private'
39
+ )
40
+ p schedule
41
+ puts
42
+ puts '------------'
43
+ puts
44
+
45
+ puts 'schedule.events.create'
46
+ event = schedule.events.create(
47
+ name: 'Cool Event',
48
+ description: 'Look at it go',
49
+ when: {
50
+ "period" => "minute",
51
+ "startDate" => "2017-05-07T22:00:00-04:00",
52
+ "endDate" => nil,
53
+ "startTimezone" => "America/New_York",
54
+ "endTimezone" => nil
55
+ }
56
+ )
57
+ p event
58
+ puts
59
+ puts '------------'
60
+ puts
61
+
62
+ puts 'schedule.events.all'
63
+ p schedule.events.all
64
+ puts
65
+ puts '------------'
66
+ puts
67
+
68
+ puts 'event.delete'
69
+ p event.delete
70
+ puts
71
+ puts '------------'
72
+ puts
73
+
74
+ client.schedules.all.each do |schedule|
75
+ p schedule.delete if schedule.name == 'Hello World'
76
+ end
77
+
78
+ __END__
79
+
80
+ TODO:
81
+ schedule.events.delete(event_ids)
82
+ schedule.upload_image(url)
83
+ event.upload_image(url)
@@ -0,0 +1,8 @@
1
+ require 'whenhub/version'
2
+ require 'whenhub/client'
3
+
4
+ module WhenHub
5
+ def self.client(access_token:)
6
+ WhenHub::Client.new(access_token: access_token)
7
+ end
8
+ end
@@ -0,0 +1,44 @@
1
+ require 'whenhub/user'
2
+ require 'whenhub/schedules_collection'
3
+ require 'whenhub/schedule'
4
+ require 'whenhub/events_collection'
5
+ require 'whenhub/event'
6
+
7
+ require 'rest-client'
8
+ require 'json'
9
+
10
+ module WhenHub
11
+ class Client
12
+ RESOURCE = RestClient::Resource.new('https://api.whenhub.com')
13
+
14
+ def initialize(access_token:)
15
+ @access_token = access_token
16
+ end
17
+
18
+ def me
19
+ User.build(self, get('/api/users/me'))
20
+ end
21
+
22
+ def schedules
23
+ SchedulesCollection.new(self)
24
+ end
25
+
26
+ def get(path, params={})
27
+ JSON.parse(nested_resource(path).get(params: params))
28
+ end
29
+
30
+ def post(path, params={})
31
+ JSON.parse(nested_resource(path).post(params))
32
+ end
33
+
34
+ def delete(path)
35
+ JSON.parse(nested_resource(path).delete)
36
+ end
37
+
38
+ private
39
+
40
+ def nested_resource(path)
41
+ RESOURCE[path + "?access_token=#{@access_token}"]
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,55 @@
1
+ require 'virtus'
2
+
3
+ module WhenHub
4
+ class Event
5
+ include Virtus.model
6
+
7
+ attribute :when, Hash
8
+ attribute :name, String
9
+ attribute :description, String
10
+ attribute :icon, String
11
+ attribute :location, Hash
12
+ attribute :resources, Array
13
+ attribute :priority, String
14
+ attribute :draft, Boolean
15
+ attribute :tags, Array
16
+ attribute :order, Integer
17
+ attribute :customFieldData, Hash
18
+ attribute :id, String
19
+ attribute :userId, String
20
+ attribute :createdAt, Time
21
+ attribute :updatedAt, Time
22
+ attribute :createdBy, String
23
+ attribute :updatedBy, String
24
+ attribute :scheduleId, String
25
+
26
+ attr_accessor :client
27
+
28
+ def self.build(client, schedule, attributes)
29
+ new(attributes).tap do |event|
30
+ event.client = client
31
+ event.scheduleId = schedule.id
32
+ end
33
+ end
34
+
35
+ def save
36
+ self.attributes = @client.post(
37
+ "/api/users/me/schedules/#{scheduleId}/events",
38
+ writeable_attributes
39
+ ).first
40
+ end
41
+
42
+ def writeable_attributes
43
+ {
44
+ when: self.when,
45
+ name: name,
46
+ description: description,
47
+ scheduleId: scheduleId
48
+ }
49
+ end
50
+
51
+ def delete
52
+ @client.delete("/api/events/#{id}")
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,22 @@
1
+ module WhenHub
2
+ class EventsCollection
3
+ def initialize(client, schedule)
4
+ @client = client
5
+ @schedule = schedule
6
+ end
7
+
8
+ def all
9
+ @client.get("/api/users/me/schedules/#{@schedule.id}/events").map do |attributes|
10
+ Event.build(@client, @schedule, attributes)
11
+ end
12
+ end
13
+
14
+ def build(attributes = {})
15
+ Event.build(@client, @schedule, attributes)
16
+ end
17
+
18
+ def create(attributes = {})
19
+ build(attributes).tap(&:save)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,52 @@
1
+ require 'virtus'
2
+
3
+ module WhenHub
4
+ class Schedule
5
+ include Virtus.model
6
+
7
+ attribute :calendar, Hash
8
+ attribute :name, String
9
+ attribute :description, String
10
+ attribute :curator, String
11
+ attribute :scope, String
12
+ attribute :viewCode, String
13
+ attribute :tags, Array
14
+ attribute :id, String
15
+ attribute :userId, String
16
+ attribute :createdAt, Time
17
+ attribute :updatedAt, Time
18
+ attribute :createdBy, String
19
+ attribute :updatedBy, String
20
+
21
+ attr_accessor :client
22
+
23
+ def self.build(client, attributes)
24
+ new(attributes).tap do |schedule|
25
+ schedule.client = client
26
+ end
27
+ end
28
+
29
+ def save
30
+ self.attributes = @client.post(
31
+ '/api/users/me/schedules',
32
+ writeable_attributes
33
+ )
34
+ end
35
+
36
+ def writeable_attributes
37
+ {
38
+ name: name,
39
+ description: description,
40
+ scope: scope
41
+ }
42
+ end
43
+
44
+ def delete
45
+ @client.delete("/api/schedules/#{id}")
46
+ end
47
+
48
+ def events
49
+ EventsCollection.new(client, self)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,31 @@
1
+ module WhenHub
2
+ class SchedulesCollection
3
+ def initialize(client)
4
+ @client = client
5
+ end
6
+
7
+ def all
8
+ @client.get('/api/users/me/schedules').map do |attributes|
9
+ Schedule.build(@client, attributes)
10
+ end
11
+ end
12
+
13
+ def find(schedule_id, media: false)
14
+ params = {
15
+ 'filter[include][events]' => ['media'],
16
+ 'filter[include]' => ['media']
17
+ }
18
+
19
+ attributes = @client.get("/api/users/me/schedules/#{schedule_id}", params)
20
+ Schedule.build(@client, attributes)
21
+ end
22
+
23
+ def build(attributes = {})
24
+ Schedule.build(@client, attributes)
25
+ end
26
+
27
+ def create(attributes = {})
28
+ build(attributes).tap(&:save)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ require 'virtus'
2
+
3
+ module WhenHub
4
+ class User
5
+ include Virtus.model
6
+
7
+ attribute :displayName, String
8
+ attribute :photo, String
9
+ attribute :login, Time
10
+ attribute :twoFactor, Boolean
11
+ attribute :username, String
12
+ attribute :id, String
13
+ attribute :createdAt, Time
14
+ attribute :updatedAt, Time
15
+ attribute :schedulesFollowed, Array
16
+
17
+ attr_accessor :client
18
+
19
+ def self.build(client, attributes)
20
+ new(attributes).tap do |schedule|
21
+ schedule.client = client
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module WhenHub
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'whenhub/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "whenhub"
8
+ spec.version = WhenHub::VERSION
9
+ spec.authors = ["Matt Gillooly"]
10
+ spec.email = ["git@mattgillooly.com"]
11
+
12
+ spec.description = %q{a gem for the WhenHub API}
13
+ spec.summary = spec.description
14
+ spec.homepage = 'http://github.com/mattgillooly/whenhub'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'rest-client'
24
+ spec.add_dependency 'virtus'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whenhub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Gillooly
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
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: virtus
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.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
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: a gem for the WhenHub API
84
+ email:
85
+ - git@mattgillooly.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - bin/test
99
+ - lib/whenhub.rb
100
+ - lib/whenhub/client.rb
101
+ - lib/whenhub/event.rb
102
+ - lib/whenhub/events_collection.rb
103
+ - lib/whenhub/schedule.rb
104
+ - lib/whenhub/schedules_collection.rb
105
+ - lib/whenhub/user.rb
106
+ - lib/whenhub/version.rb
107
+ - whenhub.gemspec
108
+ homepage: http://github.com/mattgillooly/whenhub
109
+ licenses: []
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.5.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: a gem for the WhenHub API
131
+ test_files: []