clickmeetings 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +5 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +41 -0
  8. data/Rakefile +6 -0
  9. data/bin/console +11 -0
  10. data/bin/setup +8 -0
  11. data/clickmeetings.gemspec +31 -0
  12. data/lib/.DS_Store +0 -0
  13. data/lib/clickmeetings.rb +46 -0
  14. data/lib/clickmeetings/.DS_Store +0 -0
  15. data/lib/clickmeetings/client.rb +64 -0
  16. data/lib/clickmeetings/config.rb +11 -0
  17. data/lib/clickmeetings/engine.rb +12 -0
  18. data/lib/clickmeetings/exceptions.rb +19 -0
  19. data/lib/clickmeetings/model.rb +138 -0
  20. data/lib/clickmeetings/models/open_api/.keep +0 -0
  21. data/lib/clickmeetings/models/privatelabel/account.rb +37 -0
  22. data/lib/clickmeetings/models/privatelabel/conference.rb +63 -0
  23. data/lib/clickmeetings/models/privatelabel/profile.rb +23 -0
  24. data/lib/clickmeetings/version.rb +3 -0
  25. data/spec/clickmeetings_spec.rb +7 -0
  26. data/spec/client_spec.rb +37 -0
  27. data/spec/fixtures/delete_accounts_1_conferences_1.json +1 -0
  28. data/spec/fixtures/delete_models_1.json +1 -0
  29. data/spec/fixtures/get_accounts_1_conferences.json +1 -0
  30. data/spec/fixtures/get_accounts_1_conferences_1.json +1 -0
  31. data/spec/fixtures/get_client.json +31 -0
  32. data/spec/fixtures/get_models.json +1 -0
  33. data/spec/fixtures/get_models_1.json +1 -0
  34. data/spec/fixtures/post_accounts_1_conferences.json +1 -0
  35. data/spec/fixtures/post_models.json +1 -0
  36. data/spec/fixtures/put_accounts_1_conferences_1.json +1 -0
  37. data/spec/fixtures/put_accounts_1_disable.json +1 -0
  38. data/spec/fixtures/put_accounts_1_enable.json +1 -0
  39. data/spec/fixtures/put_models_1.json +1 -0
  40. data/spec/helpers/fixtures_helpers.rb +11 -0
  41. data/spec/helpers/webmock_helpers.rb +20 -0
  42. data/spec/model_spec.rb +84 -0
  43. data/spec/models/privatelabel/account_spec.rb +38 -0
  44. data/spec/models/privatelabel/conference_spec.rb +144 -0
  45. data/spec/models/privatelabel/profile_spec.rb +19 -0
  46. data/spec/shared_examples/conferences_examples.rb +6 -0
  47. data/spec/spec_helper.rb +19 -0
  48. metadata +263 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2eb3acae05e1d5649ffeba362990811c515842ce
4
+ data.tar.gz: dc3bd99acd772dc6aaf8a427d32d8ca925ec35ac
5
+ SHA512:
6
+ metadata.gz: 4838201083a7e921890ac862b3e576f5730d56f94ebf9efe0de05bf0f788bad3aa08682227df486ab1bcd920fc61fe157bbb8ee8a49858f3af10e4efbf199355
7
+ data.tar.gz: 2b6da840b51cd4c662e6bc675652877a8ba8e6666beac9d2e1174ab32fc5443d817034377bc40f19b6653e62f99ea8ad4abde1ab9231a16d8bc355ce5f7bb42e
@@ -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
+ /.DS_Store
11
+ examples.txt
12
+ /clickmeetings.yml
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.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'faraday'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Sergei Alekseenko
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,41 @@
1
+ # Clickmeetings
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/clickmeetings`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'clickmeetings'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install clickmeetings
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/clickmeetings.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -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,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "clickmeetings"
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
@@ -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,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'clickmeetings/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "clickmeetings"
8
+ spec.version = Clickmeetings::VERSION
9
+ spec.authors = ["Sergei Alekseenko", "Makar Ermokhin"]
10
+ spec.email = ["alekseenkoss@gmail.com", "ermak95@gmail.com"]
11
+ spec.summary = %q{Simple REST API client for ClickMeetings Private Label API}
12
+ spec.description = %q{Simple REST API client for ClickMeetings Private Label API}
13
+ spec.homepage = "https://github.com/teachbase/clickmeetings"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "webmock", "~> 2"
25
+ spec.add_development_dependency 'pry', "~> 0.10"
26
+ spec.add_dependency "anyway_config", "~> 0", ">= 0.3"
27
+ spec.add_dependency "faraday", "~> 0.9"
28
+ spec.add_dependency "faraday_middleware", "~> 0.10"
29
+ spec.add_dependency 'activemodel', "~> 4.1"
30
+ spec.add_dependency 'json', '~> 1.0'
31
+ end
Binary file
@@ -0,0 +1,46 @@
1
+ require 'clickmeetings/version'
2
+ require 'clickmeetings/config'
3
+ require 'clickmeetings/client'
4
+ require 'clickmeetings/model'
5
+ require 'clickmeetings/exceptions'
6
+
7
+ module Clickmeetings
8
+ def self.config
9
+ @config ||= Config.new
10
+ end
11
+
12
+ def self.properties
13
+ client.properties
14
+ end
15
+
16
+ def self.configure
17
+ yield(config) if block_given?
18
+ end
19
+
20
+ def self.client
21
+ ClientRegistry.client || (@client ||= Client.new)
22
+ end
23
+
24
+ def self.reset
25
+ @config = nil
26
+ @client = nil
27
+ end
28
+
29
+ def self.with_client(client)
30
+ client = Client.new(client) unless client.is_a?(Client)
31
+ ClientRegistry.client = client
32
+ result = yield
33
+ ClientRegistry.client = nil
34
+ result
35
+ end
36
+
37
+ class ClientRegistry # :nodoc:
38
+ extend ActiveSupport::PerThreadRegistry
39
+
40
+ attr_accessor :client
41
+ end
42
+
43
+ require 'clickmeetings/engine' if defined?(Rails)
44
+ Gem.find_files('clickmeetings/models/open_api/*.rb').each { |f| require f }
45
+ Gem.find_files('clickmeetings/models/privatelabel/*.rb').each { |f| require f }
46
+ end
@@ -0,0 +1,64 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'json'
4
+
5
+ module Clickmeetings
6
+ class Client
7
+ attr_reader :url, :api_key
8
+
9
+ def initialize(url: Clickmeetings.config.host,
10
+ api_key: Clickmeetings.config.api_key)
11
+
12
+ @url = url
13
+ @api_key = api_key
14
+
15
+ @connect = Faraday.new(url: url) do |faraday|
16
+ faraday.adapter Faraday.default_adapter
17
+ faraday.use :instrumentation
18
+ end
19
+ end
20
+
21
+ def connect
22
+ @connect || self.class.new
23
+ end
24
+
25
+ def request(method, url, &block)
26
+ unless connect.respond_to?(method)
27
+ fail Clickmeetings::UndefinedHTTPMethod, "method: #{method}"
28
+ end
29
+
30
+ handle_response(connect.send(method, url, &block))
31
+ end
32
+
33
+ def handle_response(response)
34
+ case response.status
35
+ when 200, 201
36
+ body = response.body
37
+ body = JSON.parse body unless body == "true"
38
+ body
39
+ when 400
40
+ fail Clickmeetings::BadRequestError, response.body
41
+ when 401
42
+ fail Clickmeetings::Unauthorized, response.body
43
+ when 403
44
+ fail Clickmeetings::Forbidden, response.body
45
+ when 404
46
+ fail Clickmeetings::NotFound, response.body
47
+ when 422
48
+ fail Clickmeetings::UnprocessedEntity, response.body
49
+ when 500
50
+ fail Clickmeetings::InternalServerError, response.body
51
+ end
52
+ end
53
+
54
+ %w(get post put patch delete).each do |method|
55
+ define_method method do |url, params = {}|
56
+ l = lambda do |req|
57
+ req.headers["Content-Type"] = "application/x-www-form-urlencoded"
58
+ req.body = params.merge(api_key: api_key).to_query
59
+ end
60
+ request(method, url, &l)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ require 'anyway'
2
+
3
+ module Clickmeetings
4
+ class Config < Anyway::Config
5
+ config_name :clickmeetings
6
+ attr_config privatelabel_host: 'https://api.clickmeeting.com/privatelabel/v1',
7
+ host: 'https://api.clickmeeting.com/v1',
8
+ api_key: 'test_key',
9
+ privatelabel_api_key: 'privatelabel_api_key'
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'clickmeetings'
2
+ require 'rails'
3
+
4
+ module Clickmeetings
5
+ # Clickmeeting Rails engine
6
+ # Load Clickmeetings rake tasks
7
+ class Engine < Rails::Engine
8
+ rake_tasks do
9
+ load File.expand_path("../../tasks/clickmeetings.rake", __FILE__)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module Clickmeetings
2
+ class ClickmeetingError < ::StandardError; end
3
+
4
+ class Clickmeetings::BadRequestError < ClickmeetingError; end
5
+
6
+ class Clickmeetings::UndefinedHTTPMethod < ClickmeetingError; end
7
+
8
+ class Clickmeetings::Unauthorized < ClickmeetingError; end
9
+
10
+ class Clickmeetings::Forbidden < ClickmeetingError; end
11
+
12
+ class Clickmeetings::NotFound < ClickmeetingError; end
13
+
14
+ class Clickmeetings::Invalid < ClickmeetingError; end
15
+
16
+ class UnprocessedEntity < ClickmeetingError; end
17
+
18
+ class Clickmeetings::InternalServerError < ClickmeetingError; end
19
+ end
@@ -0,0 +1,138 @@
1
+ require 'clickmeetings'
2
+ require 'active_model'
3
+
4
+ module Clickmeetings
5
+ class Model
6
+ include ActiveModel::Model
7
+ include ActiveModel::AttributeMethods
8
+ include ActiveModel::Validations
9
+
10
+ attr_accessor :id
11
+
12
+ class << self
13
+ attr_accessor :resource_name
14
+ attr_reader :client_host, :client_api_key
15
+
16
+ delegate :remote_url, :remote_path, :handle_response, :client, to: :new
17
+
18
+ def resource_name
19
+ @resource_name ||= self.name.demodulize.pluralize.downcase
20
+ end
21
+
22
+ def find(id)
23
+ response = Clickmeetings.with_client(client_options) do
24
+ client.get(remote_url(__method__, id: id))
25
+ end
26
+ handle_response(response)
27
+ end
28
+
29
+ def all
30
+ response = Clickmeetings.with_client(client_options) do
31
+ client.get(remote_url(__method__))
32
+ end
33
+ handle_response(response)
34
+ end
35
+
36
+ def create(params = {})
37
+ response = Clickmeetings.with_client(client_options) do
38
+ client.post(remote_url(__method__), params)
39
+ end
40
+ handle_response(response)
41
+ end
42
+
43
+ def set_resource_name(name)
44
+ @resource_name = name
45
+ end
46
+
47
+ def set_client_host(host = nil)
48
+ @client_host = host
49
+ end
50
+
51
+ def set_client_api_key(api_key = nil)
52
+ @client_api_key = api_key
53
+ end
54
+
55
+ def client_options
56
+ {
57
+ url: @client_host ||= Clickmeetings.config.host,
58
+ api_key: @client_api_key ||= Clickmeetings.config.api_key
59
+ }
60
+ end
61
+ end
62
+
63
+ delegate :resource_name, to: :class
64
+
65
+ def client
66
+ Clickmeetings.client
67
+ end
68
+
69
+ def remote_url(action = nil, params = {})
70
+ url = remote_path(action, params)
71
+ end
72
+
73
+ def persist?
74
+ !!id
75
+ end
76
+
77
+ def update(params = {})
78
+ response = Clickmeetings.with_client(client_options) do
79
+ client.put(remote_url(__method__), params)
80
+ end
81
+ handle_response response
82
+ end
83
+
84
+ def destroy(params = {})
85
+ Clickmeetings.with_client(client_options) { client.delete(remote_url(__method__), params) }
86
+ self
87
+ end
88
+
89
+ def handle_response(body)
90
+ return unless [Hash, Array].include? body.class
91
+ merge_attributes(body)
92
+ end
93
+
94
+ def remote_path(action = nil, params = {})
95
+ case action
96
+ when :all
97
+ resource_name
98
+ when :find
99
+ "#{resource_name}/#{params[:id]}"
100
+ when :create
101
+ resource_name
102
+ when :update
103
+ "#{resource_name}/#{id}"
104
+ when :destroy
105
+ "#{resource_name}/#{id}"
106
+ else
107
+ "#{resource_name}/#{params[:id]}/#{action}"
108
+ end
109
+ end
110
+
111
+ private
112
+
113
+ delegate :client_options, to: :class
114
+
115
+ def merge_attributes(attrs)
116
+ if attrs.is_a?(Array)
117
+ merge_collection(attrs)
118
+ else
119
+ merge_object(attrs)
120
+ end
121
+ end
122
+
123
+ def merge_collection(attrs)
124
+ attrs.map { |e| self.class.new.handle_response(e) }
125
+ end
126
+
127
+ def merge_object(attrs)
128
+ attrs.each do |attribute, val|
129
+ if respond_to?(attribute)
130
+ send("#{attribute}=", val)
131
+ elsif val.is_a? Hash
132
+ merge_object val
133
+ end
134
+ end
135
+ self
136
+ end
137
+ end
138
+ end