myxy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env +1 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +52 -0
- data/.sample.env +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/README.md +100 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/myxy.rb +30 -0
- data/lib/myxy/classifier.rb +28 -0
- data/lib/myxy/client.rb +39 -0
- data/lib/myxy/config.rb +58 -0
- data/lib/myxy/log.rb +17 -0
- data/lib/myxy/request.rb +49 -0
- data/lib/myxy/resource.rb +104 -0
- data/lib/myxy/resources/calendar.rb +25 -0
- data/lib/myxy/resources/event.rb +18 -0
- data/lib/myxy/response.rb +45 -0
- data/lib/myxy/utils.rb +35 -0
- data/lib/myxy/version.rb +7 -0
- data/myxy.gemspec +35 -0
- metadata +264 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6cbed619c6e370cac90567f1ab6381b1c5ac6ccf
|
4
|
+
data.tar.gz: ae9d6dda9a60adbae85fc6bf52ce61c06c5ba4a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cdb0af05a8495f238cd062fc12d054c5340bef0959200bb1d2ce4623499c9b87f9794a7bbafee7cf52f931a3aba89ca9233f1f64ea38825a8df30563de221980
|
7
|
+
data.tar.gz: 006b12fe49478d739892bd66caf7323f3c4a78ddf13c0032e85cefaf9f1a026ff565ad26dedef2713971b55ec0dfcc846181f7e4333f9b46b200647c2ea47d70
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
Documentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
Include:
|
6
|
+
- '**/Rakefile'
|
7
|
+
- '**/config.ru'
|
8
|
+
Exclude:
|
9
|
+
- 'db/**/*'
|
10
|
+
- 'tmp/**/*'
|
11
|
+
- 'vendor/**/*'
|
12
|
+
- 'bin/**/*'
|
13
|
+
- 'log/**/*'
|
14
|
+
- 'spec/**/*'
|
15
|
+
- 'config/**/*'
|
16
|
+
- 'demos/**/*'
|
17
|
+
RunRailsCops: true
|
18
|
+
|
19
|
+
Metrics/AbcSize:
|
20
|
+
Max: 30
|
21
|
+
Metrics/BlockNesting:
|
22
|
+
Max: 3
|
23
|
+
Metrics/ClassLength:
|
24
|
+
CountComments: false # count full line comments?
|
25
|
+
Max: 100
|
26
|
+
Metrics/CyclomaticComplexity:
|
27
|
+
Max: 6
|
28
|
+
Metrics/LineLength:
|
29
|
+
Max: 150
|
30
|
+
AllowURI: true
|
31
|
+
URISchemes:
|
32
|
+
- http
|
33
|
+
- https
|
34
|
+
|
35
|
+
Metrics/MethodLength:
|
36
|
+
CountComments: false # count full line comments?
|
37
|
+
Max: 13
|
38
|
+
|
39
|
+
Metrics/ParameterLists:
|
40
|
+
Max: 5
|
41
|
+
CountKeywordArgs: true
|
42
|
+
|
43
|
+
Metrics/PerceivedComplexity:
|
44
|
+
Max: 7
|
45
|
+
Style/PerlBackrefs:
|
46
|
+
Enabled: false
|
47
|
+
Lint/AmbiguousOperator:
|
48
|
+
Enabled: false
|
49
|
+
Rails/Delegate:
|
50
|
+
Enabled: false
|
51
|
+
EachWithObject:
|
52
|
+
Enabled: false
|
data/.sample.env
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
API_TOKEN=yourtoken
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
guard :rspec, cmd: 'rspec' do
|
2
|
+
watch(%r{^spec/.+_spec\.rb$})
|
3
|
+
watch(%r{^lib/(.+)\.rb$}) { "spec" }
|
4
|
+
watch('spec/spec_helper.rb') { "spec" }
|
5
|
+
end
|
6
|
+
|
7
|
+
guard :rubocop, all_on_start: false, cli: ['--format', 'clang', '--rails'] do
|
8
|
+
watch(%r{^spec/.+_spec\.rb$})
|
9
|
+
watch(%r{^lib/(.+)\.rb$})
|
10
|
+
watch('spec/spec_helper.rb')
|
11
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/Marthyn/myxy.svg?branch=master)](https://travis-ci.org/Marthyn/myxy)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/Marthyn/myxy/badges/gpa.svg)](https://codeclimate.com/github/Marthyn/myxy)
|
3
|
+
# Myxy
|
4
|
+
*Short for Myxomatosis, one of my favourite Radiohead songs*
|
5
|
+
|
6
|
+
Myxy is an API wrapper written in Ruby for the great Calendar42 app.
|
7
|
+
|
8
|
+
To try this Gem out in an example app, check this repo out https://github.com/Marthyn/myxy-demo.
|
9
|
+
|
10
|
+
## Calendar42
|
11
|
+
*From docs.calendar42.com*
|
12
|
+
|
13
|
+
Calendar42 is a planning ecosystem that distributes, enriches and profiles time related information. It communicates in real-time with end-users through our browser- & native apps, as well as our our other communication channels. We offer SMS text (not everyone one has a smartphone), transactional mail (nothing wrong with good old fashioned mailboxes) & native push notifications including custom templates & notification masks.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'myxy'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install myxy
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
First you'll need to implement an authentication part. You can use the built in authenticaton method and enter your credentials in environment variables but if you're gonna develop an app that let's other users login then you should build an HTML page where users can enter credentials and login to their Calendar42 account. Then you'll only have to set the `Myxy.config.api_token`.
|
34
|
+
|
35
|
+
### Resources in this Gem
|
36
|
+
|
37
|
+
#### Events
|
38
|
+
|
39
|
+
e.g.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Myxy::Event.all
|
43
|
+
```
|
44
|
+
Will return all events.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
Myxy::Event.where(type: 'todo')
|
48
|
+
```
|
49
|
+
Will return all events of the type todo.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
Myxy::Event.find_by(title: 'Dinner at the restaurant at the end of the Universe')
|
53
|
+
```
|
54
|
+
Will return the event with that title if it exists.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
Myxy::Event.find(1)
|
58
|
+
```
|
59
|
+
Will return the event with id 1 if it exists.
|
60
|
+
|
61
|
+
## TODO
|
62
|
+
|
63
|
+
* Demo application
|
64
|
+
* Subscriptions
|
65
|
+
* Locations
|
66
|
+
* Services
|
67
|
+
* Relationships
|
68
|
+
* Actors/Persons
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
73
|
+
|
74
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
*You know the drill*
|
78
|
+
|
79
|
+
1. Fork it ( https://github.com/[my-github-username]/myxy/fork )
|
80
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
82
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
83
|
+
5. Create a new Pull Request
|
84
|
+
|
85
|
+
## Testing
|
86
|
+
|
87
|
+
We use Rspec for normal unit testing. We aim for coverage above 90%. Also the current suite should succeed when you commit something.
|
88
|
+
We use Rubocop for style checking, this should also succeed before you commit anything.
|
89
|
+
|
90
|
+
We're also experimenting with Mutation testing, which alters your code to test if your specs fail when there's faulty code. This is important when you
|
91
|
+
alter a vital part of the code, make sure the mutation percentage is higher than 80%. To run a part of the code with mutant run the follwing
|
92
|
+
`mutant --include lib/myxy --require myxy --use rspec Myxy::ClassYoureWorkingOn`
|
93
|
+
|
94
|
+
When you're editing code it's advised you run guard, which watches file changes and automatically runs Rspec and Rubocop.
|
95
|
+
|
96
|
+
## Me
|
97
|
+
|
98
|
+
[I've](http://www.marthyn.nl) created this gem because I like doing it but also because I believe in Calendar42 as a product.
|
99
|
+
|
100
|
+
[![forthebadge](http://forthebadge.com/images/badges/built-with-ruby.svg)](http://www.marthyn.nl)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'myxy'
|
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
data/lib/myxy.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'myxy/version'
|
2
|
+
require 'myxy/client'
|
3
|
+
require 'myxy/config'
|
4
|
+
require 'myxy/response'
|
5
|
+
require 'myxy/utils'
|
6
|
+
require 'myxy/resource'
|
7
|
+
require 'myxy/resources/event'
|
8
|
+
require 'myxy/resources/calendar'
|
9
|
+
require 'dotenv'
|
10
|
+
Dotenv.load
|
11
|
+
|
12
|
+
module Myxy
|
13
|
+
extend Config
|
14
|
+
# extend Log
|
15
|
+
|
16
|
+
def self.client(options = {})
|
17
|
+
Myxy::Client.new(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Delegate method to client
|
21
|
+
def self.method_missing(method, *args, &block)
|
22
|
+
super unless client.respond_to?(method)
|
23
|
+
client.send(method, *args, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Delegate method to client
|
27
|
+
def self.respond_to?(method, include_all = false)
|
28
|
+
client.respond_to?(method, include_all) || super
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../log', __FILE__)
|
2
|
+
|
3
|
+
module Myxy
|
4
|
+
class Classifier
|
5
|
+
def self.parse(data, klass)
|
6
|
+
if data.is_a? Array
|
7
|
+
Classifier.multiple(data, klass)
|
8
|
+
else
|
9
|
+
Classifier.create_object(data, klass)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.multiple(resources, klass)
|
14
|
+
results = []
|
15
|
+
resources.each do |resource|
|
16
|
+
results << Classifier.create_object(resource, klass)
|
17
|
+
end
|
18
|
+
results
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.create_object(resource, klass)
|
22
|
+
Module.const_get(klass).new(resource)
|
23
|
+
rescue NameError => e
|
24
|
+
Log.info("Unkown resource found, #{e.message}")
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/myxy/client.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'uri'
|
3
|
+
require File.expand_path('../request', __FILE__)
|
4
|
+
require File.expand_path('../config', __FILE__)
|
5
|
+
|
6
|
+
module Myxy
|
7
|
+
class Client
|
8
|
+
attr_accessor *(Config::VALID_OPTIONS_KEYS)
|
9
|
+
|
10
|
+
# Creates a new API
|
11
|
+
def initialize(options = {})
|
12
|
+
options = Myxy.options.merge(options)
|
13
|
+
Config::VALID_OPTIONS_KEYS.each do |key|
|
14
|
+
send("#{key}=", options[key])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def connection
|
19
|
+
Faraday.new(url) do |faraday|
|
20
|
+
faraday.adapter Faraday.default_adapter
|
21
|
+
faraday.port = 443
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def url
|
26
|
+
URI.join(base_url, version)
|
27
|
+
end
|
28
|
+
|
29
|
+
def config
|
30
|
+
conf = {}
|
31
|
+
Config::VALID_OPTIONS_KEYS.each do |key|
|
32
|
+
conf[key] = send key
|
33
|
+
end
|
34
|
+
conf
|
35
|
+
end
|
36
|
+
|
37
|
+
include Request
|
38
|
+
end
|
39
|
+
end
|
data/lib/myxy/config.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Myxy
|
4
|
+
module Config
|
5
|
+
# An array of valid keys in the options hash
|
6
|
+
VALID_OPTIONS_KEYS = [
|
7
|
+
:api_token,
|
8
|
+
:adapter,
|
9
|
+
:connection_options,
|
10
|
+
:response_format,
|
11
|
+
:version,
|
12
|
+
:base_url
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
# The adapter that will be used to connect if none is set
|
16
|
+
#
|
17
|
+
# @note The default faraday adapter is Net::HTTP.
|
18
|
+
DEFAULT_ADAPTER = Faraday.default_adapter
|
19
|
+
|
20
|
+
# Version V2 is the only valid version at the moment
|
21
|
+
DEFAULT_VERSION = 'v2'
|
22
|
+
|
23
|
+
# Base url is beta now
|
24
|
+
DEFAULT_BASE_URL = 'https://beta.calendar42.com/app/django/api/'
|
25
|
+
|
26
|
+
DEFAULT_FORMAT = :json
|
27
|
+
|
28
|
+
# @private
|
29
|
+
attr_accessor *(VALID_OPTIONS_KEYS)
|
30
|
+
|
31
|
+
# When this module is extended, set all configuration options to their default values
|
32
|
+
def self.extended(base)
|
33
|
+
base.reset
|
34
|
+
end
|
35
|
+
|
36
|
+
# Convenience method to allow configuration options to be set in a block
|
37
|
+
def configure
|
38
|
+
yield self
|
39
|
+
end
|
40
|
+
|
41
|
+
# Create a hash of options and their values
|
42
|
+
def options
|
43
|
+
VALID_OPTIONS_KEYS.inject({}) do |option, key|
|
44
|
+
option.merge!(key => send(key))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Reset all configuration options to defaults
|
49
|
+
def reset
|
50
|
+
self.adapter = DEFAULT_ADAPTER
|
51
|
+
self.api_token = ENV['API_TOKEN']
|
52
|
+
self.connection_options = nil
|
53
|
+
self.base_url = DEFAULT_BASE_URL
|
54
|
+
self.version = DEFAULT_VERSION
|
55
|
+
self.response_format = DEFAULT_FORMAT
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/myxy/log.rb
ADDED
data/lib/myxy/request.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Myxy
|
2
|
+
# Defines HTTP request methods
|
3
|
+
module Request
|
4
|
+
# Perform an HTTP GET request
|
5
|
+
def get(path, options = {})
|
6
|
+
request(:get, path, options)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Perform an HTTP POST request
|
10
|
+
def post(path, options = {})
|
11
|
+
request(:post, path, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Perform an HTTP PUT request
|
15
|
+
def put(path, options = {})
|
16
|
+
request(:put, path, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Perform an HTTP DELETE request
|
20
|
+
def delete(path, options = {})
|
21
|
+
request(:delete, path, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def build_headers
|
27
|
+
headers = {}
|
28
|
+
headers['Content-Type'] = "application/#{response_format}"
|
29
|
+
headers['Accept'] = "application/#{response_format}"
|
30
|
+
headers['Authorization'] = "Token #{api_token}" if api_token
|
31
|
+
headers
|
32
|
+
end
|
33
|
+
|
34
|
+
# Perform an HTTP request
|
35
|
+
def request(method, path, options = {})
|
36
|
+
response = connection.send(method) do |request|
|
37
|
+
case method
|
38
|
+
when :post, :put
|
39
|
+
request.url path
|
40
|
+
request.body = options[:params].to_json
|
41
|
+
when :get, :delete
|
42
|
+
request.url path
|
43
|
+
end
|
44
|
+
request.headers = build_headers
|
45
|
+
end
|
46
|
+
Response.new(response)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require File.expand_path('../utils', __FILE__)
|
3
|
+
require File.expand_path('../classifier', __FILE__)
|
4
|
+
|
5
|
+
module Myxy
|
6
|
+
module Resource
|
7
|
+
attr_accessor :attributes
|
8
|
+
|
9
|
+
def initialize(attributes = {})
|
10
|
+
@attributes = Utils.normalize_attributes(attributes)
|
11
|
+
end
|
12
|
+
|
13
|
+
def base_path
|
14
|
+
Utils.collection_path self.class.name
|
15
|
+
end
|
16
|
+
|
17
|
+
def update_params(params)
|
18
|
+
params.each do |key, value|
|
19
|
+
set_attribute(key, value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def save(params = nil)
|
24
|
+
update_params(params) if params
|
25
|
+
if id
|
26
|
+
uri = "#{base_path}/#{id}/"
|
27
|
+
Myxy.put(uri.to_s, params: attributes)
|
28
|
+
else
|
29
|
+
Myxy.post(base_path, params: attributes)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module ClassMethods
|
34
|
+
def base_path
|
35
|
+
new.base_path
|
36
|
+
end
|
37
|
+
|
38
|
+
def klass_name
|
39
|
+
new.class.name
|
40
|
+
end
|
41
|
+
|
42
|
+
def get(arguments)
|
43
|
+
uri = URI(base_path)
|
44
|
+
uri.query = URI.encode_www_form(arguments)
|
45
|
+
Myxy.get("#{uri}/")
|
46
|
+
end
|
47
|
+
|
48
|
+
def find(id)
|
49
|
+
uri = URI(base_path)
|
50
|
+
parse(Myxy.get("#{uri}/#{id}/").all).first
|
51
|
+
end
|
52
|
+
|
53
|
+
def where(arguments = {})
|
54
|
+
get(arguments).all
|
55
|
+
end
|
56
|
+
|
57
|
+
def find_by(arguments = {})
|
58
|
+
parse(get(arguments).first)
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse(data)
|
62
|
+
Classifier.parse(data, klass_name)
|
63
|
+
end
|
64
|
+
|
65
|
+
def all
|
66
|
+
parse(Myxy.get("#{base_path}/").all)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.included(base)
|
71
|
+
base.extend(ClassMethods)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Getter/Setter for resource
|
75
|
+
def method_missing(method, *args, &block)
|
76
|
+
yield if block
|
77
|
+
if /^(\w+)=$/ =~ method
|
78
|
+
set_attribute($1, args[0])
|
79
|
+
else
|
80
|
+
nil unless @attributes[method.to_sym]
|
81
|
+
end
|
82
|
+
@attributes[method.to_sym]
|
83
|
+
end
|
84
|
+
|
85
|
+
def set_attribute(attribute, value)
|
86
|
+
@attributes[attribute.to_sym] = value if valid_attribute?(attribute)
|
87
|
+
end
|
88
|
+
|
89
|
+
def valid_attribute?(attribute)
|
90
|
+
valid_attributes.include?(attribute.to_sym)
|
91
|
+
end
|
92
|
+
|
93
|
+
def valid_attributes
|
94
|
+
@valid_attributes ||= mandatory_attributes.inject(other_attributes, :<<)
|
95
|
+
end
|
96
|
+
|
97
|
+
def valid?
|
98
|
+
mandatory_attributes.each do |attribute|
|
99
|
+
return false unless @attributes.key? attribute
|
100
|
+
end
|
101
|
+
true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Myxy
|
2
|
+
class Calendar
|
3
|
+
include Myxy::Resource
|
4
|
+
|
5
|
+
def other_attributes
|
6
|
+
[
|
7
|
+
:id, :created, :service_id, :name, :description, :category,
|
8
|
+
:color, :image, :sync_token, :url, :calendar_type, :first_import,
|
9
|
+
:import_failed, :permission, :previous_permission
|
10
|
+
]
|
11
|
+
end
|
12
|
+
|
13
|
+
def mandatory_attributes
|
14
|
+
[]
|
15
|
+
end
|
16
|
+
|
17
|
+
def save
|
18
|
+
false && Log.error('This resource cannot be created and or updated')
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete
|
22
|
+
false && Log.error('This resource cannot be deleted')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Myxy
|
2
|
+
class Event
|
3
|
+
include Myxy::Resource
|
4
|
+
|
5
|
+
def other_attributes
|
6
|
+
[
|
7
|
+
:calendar_ids, :start, :end, :start_timezone, :end_timezone,
|
8
|
+
:all_day, :title, :description, :color, :icon, :logo, :source_url,
|
9
|
+
:time_buffer, :start_location, :end_location, :related_event_id,
|
10
|
+
:trip, :length, :is_suggestion, :due, :rsvp_status
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
def mandatory_attributes
|
15
|
+
[:event_type]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'json'
|
2
|
+
module Myxy
|
3
|
+
class Response
|
4
|
+
attr_accessor :status_code, :body, :response
|
5
|
+
|
6
|
+
ERROR_CODES = [400, 500].freeze
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
@response = response
|
10
|
+
Log.error(error_message) if error?
|
11
|
+
end
|
12
|
+
|
13
|
+
def status_code
|
14
|
+
response.status
|
15
|
+
end
|
16
|
+
|
17
|
+
def meta
|
18
|
+
parsed_body['meta_data']
|
19
|
+
end
|
20
|
+
|
21
|
+
def parsed_body
|
22
|
+
@parsed_body ||= JSON.parse(response.body)
|
23
|
+
end
|
24
|
+
|
25
|
+
def data
|
26
|
+
parsed_body['data']
|
27
|
+
end
|
28
|
+
|
29
|
+
def error_message
|
30
|
+
parsed_body['error']['message']
|
31
|
+
end
|
32
|
+
|
33
|
+
def error?
|
34
|
+
ERROR_CODES.include? status_code
|
35
|
+
end
|
36
|
+
|
37
|
+
def first
|
38
|
+
data[0]
|
39
|
+
end
|
40
|
+
|
41
|
+
def all
|
42
|
+
data
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/myxy/utils.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Myxy
|
2
|
+
module Utils
|
3
|
+
def self.demodulize(class_name_in_module)
|
4
|
+
class_name_in_module.to_s.sub(/^.*::/, '')
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.pluralize(word)
|
8
|
+
word.to_s.sub(/([^s])$/, '\1s')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.modulize(class_name)
|
12
|
+
"Myxy::#{class_name}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.collection_path(class_name)
|
16
|
+
(Utils.pluralize Utils.demodulize class_name).downcase
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.camelize(word, uppercase_first_letter = true)
|
20
|
+
if uppercase_first_letter
|
21
|
+
word.to_s.gsub(%r{/\/(.?)/}) { '::' + $1.upcase }
|
22
|
+
.gsub(/(^|_)(.)/) { $2.upcase }
|
23
|
+
else
|
24
|
+
word[0] + Utils.camelize(word)[1..-1]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.normalize_attributes(attributes)
|
29
|
+
attributes.inject({}) do |attribute, (k, v)|
|
30
|
+
attribute[k.to_sym] = v
|
31
|
+
attribute
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/myxy/version.rb
ADDED
data/myxy.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 'myxy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "myxy"
|
8
|
+
spec.version = Myxy::VERSION
|
9
|
+
spec.authors = ["Marthyn"]
|
10
|
+
spec.email = ["Marthyn@live.nl"]
|
11
|
+
|
12
|
+
spec.summary = %q{An API wrapper for Calendar42}
|
13
|
+
spec.homepage = "https://github.com/Marthyn/myxy"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "faraday"
|
21
|
+
spec.add_dependency "json"
|
22
|
+
spec.add_dependency "ffaker"
|
23
|
+
spec.add_dependency "dotenv", "~> 2.0.2"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "pry"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "rubocop"
|
30
|
+
spec.add_development_dependency "mutant"
|
31
|
+
spec.add_development_dependency "guard-rspec"
|
32
|
+
spec.add_development_dependency "webmock"
|
33
|
+
spec.add_development_dependency "guard-rubocop"
|
34
|
+
spec.add_development_dependency "simplecov-rcov"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,264 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: myxy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marthyn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
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: json
|
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: ffaker
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: dotenv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: mutant
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: guard-rspec
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: webmock
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: guard-rubocop
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: simplecov-rcov
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
description:
|
210
|
+
email:
|
211
|
+
- Marthyn@live.nl
|
212
|
+
executables: []
|
213
|
+
extensions: []
|
214
|
+
extra_rdoc_files: []
|
215
|
+
files:
|
216
|
+
- ".env"
|
217
|
+
- ".gitignore"
|
218
|
+
- ".rspec"
|
219
|
+
- ".rubocop.yml"
|
220
|
+
- ".sample.env"
|
221
|
+
- ".travis.yml"
|
222
|
+
- Gemfile
|
223
|
+
- Guardfile
|
224
|
+
- README.md
|
225
|
+
- Rakefile
|
226
|
+
- bin/console
|
227
|
+
- bin/setup
|
228
|
+
- lib/myxy.rb
|
229
|
+
- lib/myxy/classifier.rb
|
230
|
+
- lib/myxy/client.rb
|
231
|
+
- lib/myxy/config.rb
|
232
|
+
- lib/myxy/log.rb
|
233
|
+
- lib/myxy/request.rb
|
234
|
+
- lib/myxy/resource.rb
|
235
|
+
- lib/myxy/resources/calendar.rb
|
236
|
+
- lib/myxy/resources/event.rb
|
237
|
+
- lib/myxy/response.rb
|
238
|
+
- lib/myxy/utils.rb
|
239
|
+
- lib/myxy/version.rb
|
240
|
+
- myxy.gemspec
|
241
|
+
homepage: https://github.com/Marthyn/myxy
|
242
|
+
licenses: []
|
243
|
+
metadata: {}
|
244
|
+
post_install_message:
|
245
|
+
rdoc_options: []
|
246
|
+
require_paths:
|
247
|
+
- lib
|
248
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
249
|
+
requirements:
|
250
|
+
- - ">="
|
251
|
+
- !ruby/object:Gem::Version
|
252
|
+
version: '0'
|
253
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
254
|
+
requirements:
|
255
|
+
- - ">="
|
256
|
+
- !ruby/object:Gem::Version
|
257
|
+
version: '0'
|
258
|
+
requirements: []
|
259
|
+
rubyforge_project:
|
260
|
+
rubygems_version: 2.4.5
|
261
|
+
signing_key:
|
262
|
+
specification_version: 4
|
263
|
+
summary: An API wrapper for Calendar42
|
264
|
+
test_files: []
|