ecal_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 640ccf1f3d78d04e37c4e7db19ec57da8faefc17
4
+ data.tar.gz: 368947166b4e39ed6b90785415f6c5791ff88919
5
+ SHA512:
6
+ metadata.gz: 184272b4a147b658d1a266d2bef6fca1ad61ca787b4b1b28fb1912e5fdfda4b3fece6e2326a30a2888d01321f75d170fcf0886f8f92643d70f9d79bd1540544e
7
+ data.tar.gz: 7b6cd941db4378a33d15ad1aa8d48703415288b789545764433735fbd615b83b7b250328aee88333e4fa9fa5e704b698d46a415a1b9d6ba8cb13581406d0a472
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/.rspec ADDED
@@ -0,0 +1,6 @@
1
+ --color
2
+ --format progress
3
+ --backtrace
4
+ --default-path spec
5
+
6
+
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create use ruby-2.2.3@ecal_client
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ecal_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Faizal Zakaria
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.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # EcalClient
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ecal_client`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ecal_client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ecal_client
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ ec = EcalClient::Api.new
25
+ ec.organisation.get
26
+ ec.publisher.get
27
+ ...
28
+ ec.publisher.post(options)
29
+ ```
30
+
31
+ For more details, please check `spec/ecal_client_spec.rb`.
32
+
33
+ ## Development
34
+
35
+ 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.
36
+
37
+ 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).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/faizalzakaria/ecal_client. 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.
42
+
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
47
+
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 "ecal_client"
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,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,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ecal_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ecal_client"
8
+ spec.version = EcalClient::VERSION
9
+ spec.authors = ["Faizal Zakaria"]
10
+ spec.email = ["phaibusiness@gmail.com"]
11
+
12
+ spec.summary = %q{ECal client}
13
+ spec.description = %q{ECal client gem to communicate with the ECal API.}
14
+ spec.homepage = "https://github.io/ecal_client"
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 "vcr"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "webmock"
28
+ spec.add_runtime_dependency "faraday"
29
+ end
@@ -0,0 +1,60 @@
1
+ require 'faraday'
2
+ require 'digest/md5'
3
+ require 'uri'
4
+ require 'json'
5
+
6
+ module EcalClient
7
+ class Api::Base
8
+ API_ENDPOINT = "http://client.e-diary.com".freeze
9
+
10
+ protected
11
+
12
+ def connection
13
+ @connection ||= Faraday.new(url: API_ENDPOINT) do |faraday|
14
+ faraday.request :url_encoded
15
+ faraday.response :logger if EcalClient.configuration.options[:verbose]
16
+ faraday.adapter Faraday.default_adapter
17
+ end
18
+ end
19
+
20
+ def headers
21
+ header_json
22
+ end
23
+
24
+ def api_sign(parameters = {}, body = nil)
25
+ sorted_keys = parameters.keys.sort
26
+ string = EcalClient.configuration.secret.dup
27
+ string << sorted_keys.inject("") { |memo, key| memo << "#{key}#{parameters[key]}" }
28
+ string << body.to_json if body
29
+ Digest::MD5.hexdigest(string)
30
+ end
31
+
32
+ def generate_params(params, body)
33
+ params.merge(apiSign: api_sign(params, body))
34
+ end
35
+
36
+ [:post, :get, :put].each do |method|
37
+ define_method "#{method}_call" do |action, params, body, headers|
38
+ params.merge!(apiKey: EcalClient.configuration.key)
39
+ connection.send("#{method}") do |req|
40
+ req.url action, generate_params(params, body)
41
+ req.body = body.to_json if body
42
+ req.headers = headers
43
+ end
44
+ end
45
+ end
46
+
47
+ def logging(msg)
48
+ puts "[ECAL-CLIENT] #{msg}" if EcalClient.configuration.options[:verbose]
49
+ end
50
+
51
+ private
52
+
53
+ def header_json
54
+ {
55
+ 'User-Agent' => 'Ecal Client SDK',
56
+ 'Content-Type' => 'application/json'
57
+ }
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,29 @@
1
+ module EcalClient
2
+ class Response
3
+
4
+ def initialize(response)
5
+ @response = response
6
+ end
7
+
8
+ def success?
9
+ [ 200 ].include? status
10
+ end
11
+
12
+ def status
13
+ @response.status.to_i
14
+ end
15
+
16
+ def status_long
17
+ @status_log ||= params['statusLong']
18
+ end
19
+
20
+ def params
21
+ @params ||= begin
22
+ JSON.parse(@response.body)
23
+ rescue => e
24
+ puts e.to_s if EcalClient.configuration.options[:verbose]
25
+ end
26
+ @params ||= {}
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ module EcalClient
2
+ class Api::Rest < Api::Base
3
+
4
+ class Unsupported < StandardError; end
5
+
6
+ def initialize(endpoint, actions)
7
+ @endpoint = endpoint
8
+ @actions = actions
9
+ end
10
+
11
+ def get(options = {})
12
+ raise Unsupported unless supported?(:get)
13
+ id = options.delete(:id)
14
+ endpoint = @endpoint
15
+ endpoint += id.to_s if id
16
+ response = get_call(endpoint, options, nil, headers)
17
+ Response.new(response)
18
+ end
19
+
20
+ def post(options)
21
+ raise Unsupported unless supported?(:post)
22
+ response = post_call(@endpoint, {}, options, headers)
23
+ Response.new(response)
24
+ end
25
+
26
+ def put(options)
27
+ raise Unsupported unless supported?(:put)
28
+ id = options.delete(:id)
29
+ endpoint = @endpoint
30
+ endpoint += id.to_s if id
31
+ response = put_call(endpoint, {}, options, headers)
32
+ Response.new(response)
33
+ end
34
+
35
+ private
36
+
37
+ def supported?(action)
38
+ @actions.include? action.to_sym
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ module EcalClient
2
+ class Api
3
+
4
+ API_VERSION = "/apiv2".freeze
5
+ ORGANISATION = "/organisation/".freeze
6
+ PUBLISHER = "/publisher/".freeze
7
+ CALENDAR = "/calendar/".freeze
8
+ EVENT = "/event/".freeze
9
+ SUBSCRIPTION_WIDGET = "/subscription-widget/".freeze
10
+ SUBSCRIBER = "/subscriber/".freeze
11
+
12
+ def organisation
13
+ @organisation ||= Rest.new(endpoint_for(ORGANISATION), [:get, :post, :put])
14
+ end
15
+
16
+ def publisher
17
+ @publisher ||= Rest.new(endpoint_for(PUBLISHER), [:get, :put])
18
+ end
19
+
20
+ def calendar
21
+ @calendar ||= Rest.new(endpoint_for(CALENDAR), [:get, :post, :put])
22
+ end
23
+
24
+ def event
25
+ @event ||= Rest.new(endpoint_for(EVENT), [:get, :post, :put])
26
+ end
27
+
28
+ def subscription_widget
29
+ @subscription_widget ||= Rest.new(endpoint_for(SUBSCRIPTION_WIDGET), [:get])
30
+ end
31
+
32
+ def subscriber
33
+ @subscriber ||= Rest.new(endpoint_for(SUBSCRIBER), [:get, :post, :put])
34
+ end
35
+
36
+ private
37
+
38
+ def endpoint_for(name)
39
+ API_VERSION + name
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module EcalClient
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ require "ecal_client/version"
2
+ require "ecal_client/api"
3
+ require "ecal_client/api/response"
4
+ require "ecal_client/api/base"
5
+ require "ecal_client/api/rest"
6
+
7
+ module EcalClient
8
+ class Configuration
9
+ attr_accessor :key, :secret, :options
10
+
11
+ def initialize
12
+ self.key = nil
13
+ self.secret = nil
14
+ self.options = {}
15
+ set_defaults
16
+ end
17
+
18
+ def set_defaults
19
+ options[:verbose] ||= false
20
+ options[:read_timeout] ||= 30
21
+ end
22
+ end
23
+
24
+ def self.configuration
25
+ @configuration ||= Configuration.new
26
+ end
27
+
28
+ def self.configure
29
+ yield(configuration) if block_given?
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ecal_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Faizal Zakaria
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-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: vcr
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
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: ECal client gem to communicate with the ECal API.
112
+ email:
113
+ - phaibusiness@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rvmrc"
121
+ - ".travis.yml"
122
+ - CODE_OF_CONDUCT.md
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - ecal_client.gemspec
130
+ - lib/ecal_client.rb
131
+ - lib/ecal_client/api.rb
132
+ - lib/ecal_client/api/base.rb
133
+ - lib/ecal_client/api/response.rb
134
+ - lib/ecal_client/api/rest.rb
135
+ - lib/ecal_client/version.rb
136
+ homepage: https://github.io/ecal_client
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.4.5.1
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: ECal client
160
+ test_files: []