cisco_spark 0.1.1

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: 7a5540370e43218f4fb8bb8386b58d209e98f380
4
+ data.tar.gz: 24dda8bfd4c8b55f8192a87ab698ebd2a62be3b4
5
+ SHA512:
6
+ metadata.gz: b1c8072e90d16b0773484d8719d09c6bb9679211e1ce2153951581d317c68ad25c9d45728423c6906a60370e3b220110db0d3ea38db29a1add29c11ef735002c
7
+ data.tar.gz: 9aa03be67d73155bc74674aa668a7175d6534f4278c3571a83f81fbd191a6e4b3282a954ce2f45e902d73403779f34ccf125a6e4969659d4f55cc9aa5b71152f
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .env
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.3.0
5
+ - 2.2.0
6
+ - 2.1.0
7
+ - 2.0.0
8
+ - 1.9.3
9
+ - 1.9.2
10
+ - jruby
11
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'coveralls', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nick Maher
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,42 @@
1
+ # CiscoSpark
2
+ [![Build Status](https://travis-ci.org/NGMarmaduke/cisco_spark-ruby.svg?branch=master)](https://travis-ci.org/NGMarmaduke/cisco_spark-ruby)
3
+ [![Coverage Status](https://coveralls.io/repos/github/NGMarmaduke/cisco_spark-ruby/badge.svg?branch=master)](https://coveralls.io/github/NGMarmaduke/cisco_spark-ruby?branch=master)
4
+
5
+ Ruby SDK for [Cisco Spark](https://developer.ciscospark.com).
6
+
7
+ Work in progress currently
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'cisco_spark'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install cisco_spark
24
+
25
+ ## Usage
26
+
27
+ WIP
28
+
29
+ ## Development
30
+
31
+ 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.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/NGMarmaduke/cisco_spark-ruby.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
+
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 "cisco_spark"
5
+ require "dotenv"
6
+ Dotenv.load
7
+
8
+ CiscoSpark.configure do |config|
9
+ config.debug = true
10
+ config.api_key = ENV['API_KEY']
11
+ end
12
+
13
+ require "pry"
14
+ Pry.start
data/bin/setup ADDED
@@ -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,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cisco_spark/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cisco_spark"
8
+ spec.version = CiscoSpark::VERSION
9
+ spec.authors = ["Nick Maher"]
10
+ spec.email = ["nickpmaher@gmail.com"]
11
+
12
+ spec.required_ruby_version = '>= 1.9.2'
13
+
14
+ spec.summary = "Ruby client for Cisco Spark: https://developer.ciscospark.com"
15
+ spec.homepage = "https://github.com/NGMarmaduke/cisco_spark-ruby"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "dotenv"
28
+ end
@@ -0,0 +1,27 @@
1
+ require "cisco_spark/configuration"
2
+ require "cisco_spark/errors"
3
+ require "cisco_spark/utils"
4
+ require "cisco_spark/version"
5
+
6
+ require "cisco_spark/models/membership"
7
+ require "cisco_spark/models/message"
8
+ require "cisco_spark/models/person"
9
+ require "cisco_spark/models/room"
10
+
11
+
12
+ module CiscoSpark
13
+ extend SingleForwardable
14
+ def_delegators :configuration, *Configuration.params
15
+
16
+ def self.configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def self.configure
21
+ yield(configuration)
22
+ end
23
+
24
+ def self.clear_configuration!
25
+ @configuration = Configuration.new
26
+ end
27
+ end
@@ -0,0 +1,61 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module CiscoSpark
5
+ class Api
6
+ attr_accessor :resource, :params
7
+
8
+ def initialize(resource, params={})
9
+ @resource = resource
10
+ @params = params
11
+ end
12
+
13
+ def result
14
+ response = http_client.request(request)
15
+ debug(response) if CiscoSpark.debug
16
+
17
+ if response.is_a?(Net::HTTPSuccess)
18
+ JSON.parse(response.body)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def http_client
25
+ client = Net::HTTP.new(request_uri.host, request_uri.port)
26
+ client.use_ssl = (request_uri.scheme == "https")
27
+ client
28
+ end
29
+
30
+ def request
31
+ request = Net::HTTP::Get.new(request_uri)
32
+ request['Content-type'] = "application/json; charset=utf-8"
33
+ request['Authorization'] = "Bearer #{CiscoSpark.api_key}"
34
+ debug(request) if CiscoSpark.debug
35
+ request
36
+ end
37
+
38
+ def debug(object)
39
+ puts "|============ Api debug ============ |"
40
+ puts " -> request_uri: #{request_uri.inspect}"
41
+ puts " -> object: #{object.inspect}"
42
+ puts "|============ Api debug ============ |"
43
+ end
44
+
45
+ def request_uri
46
+ uri = URI.join(domain, "#{CiscoSpark.api_version}/#{resource}")
47
+ uri.query = URI.encode_www_form(params)
48
+ uri
49
+ end
50
+
51
+ def params
52
+ @params.each_with_object({}) do |(key, value), hash|
53
+ hash[Utils.camelize(key)] = value
54
+ end
55
+ end
56
+
57
+ def domain
58
+ @domain ||= URI.join("#{CiscoSpark.api_protocol}://#{CiscoSpark.api_domain}")
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,20 @@
1
+ module CiscoSpark
2
+ class Configuration
3
+ def self.params
4
+ [:api_key, :api_version, :api_domain, :api_protocol, :debug]
5
+ end
6
+ attr_accessor *self.params
7
+
8
+ def initialize
9
+ @api_version = 'v1'
10
+ @api_domain = 'api.ciscospark.com'
11
+ @api_protocol = 'https'
12
+ @debug = false
13
+ end
14
+
15
+ def api_key
16
+ raise NoApiKeyError unless @api_key
17
+ @api_key
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ module DataCaster
2
+ Array = lambda { |data| data }
3
+ Boolean = lambda { |data| data }
4
+ String = lambda { |data| data.to_s }
5
+ DateTime = lambda { |data| ::DateTime.parse(data) }
6
+ end
@@ -0,0 +1,3 @@
1
+ module CiscoSpark
2
+ class NoApiKeyError < StandardError; end
3
+ end
@@ -0,0 +1,58 @@
1
+ require "cisco_spark/api"
2
+ require "cisco_spark/data_caster"
3
+
4
+ module CiscoSpark
5
+ module Model
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ def resource(resource)
12
+ @resource = resource
13
+ end
14
+
15
+ def attributes(hash=nil)
16
+ return @attributes unless hash
17
+
18
+ @attributes = hash
19
+ attr_accessor *@attributes.keys
20
+ end
21
+
22
+ def fetch_all(options={})
23
+ response = Api.new(@resource, options).result
24
+ parse_collection(response['items'])
25
+ end
26
+
27
+ def fetch(id, options={})
28
+ resource = "#{@resource}/#{id}"
29
+ response = Api.new(resource, options).result
30
+ parse(response)
31
+ end
32
+
33
+ def parse_collection(collection)
34
+ collection.map{ |hash| parse(hash) }
35
+ end
36
+
37
+ def parse(hash)
38
+ params = attributes.each_with_object({}) do |(attribute, caster), params|
39
+ params[attribute] = caster.call(hash[Utils.camelize(attribute)])
40
+ end
41
+ new(params)
42
+ end
43
+ end # ClassMethods
44
+
45
+ def initialize(attributes={})
46
+ assign_attributes(attributes)
47
+ end
48
+
49
+ private
50
+
51
+ def assign_attributes(attributes)
52
+ attributes.each do |name, value|
53
+ send("#{name}=", value)
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,27 @@
1
+ require "cisco_spark/model"
2
+
3
+ module CiscoSpark
4
+ class Membership
5
+ include Model
6
+ resource 'memberships'
7
+
8
+ attributes(
9
+ id: DataCaster::String,
10
+ person_id: DataCaster::String,
11
+ person_email: DataCaster::String,
12
+ person_display_name: DataCaster::String,
13
+ room_id: DataCaster::String,
14
+ is_moderator: DataCaster::Boolean,
15
+ is_monitor: DataCaster::Boolean,
16
+ created: DataCaster::DateTime,
17
+ )
18
+
19
+ def person
20
+ CiscoSpark::Person.fetch(person_id)
21
+ end
22
+
23
+ def room
24
+ CiscoSpark::Room.fetch(room_id)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ require "cisco_spark/model"
2
+
3
+ module CiscoSpark
4
+ class Message
5
+ include Model
6
+ resource 'messages'
7
+
8
+ attributes(
9
+ id: DataCaster::String,
10
+ person_id: DataCaster::String,
11
+ person_email: DataCaster::String,
12
+ room_id: DataCaster::String,
13
+ text: DataCaster::Boolean,
14
+ files: DataCaster::Array,
15
+ to_person_id: DataCaster::String,
16
+ to_person_email: DataCaster::String,
17
+ created: DataCaster::DateTime,
18
+ )
19
+
20
+ def person
21
+ CiscoSpark::Person.fetch(person_id)
22
+ end
23
+
24
+ def person_to
25
+ CiscoSpark::Person.fetch(to_person_id)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ require "cisco_spark/model"
2
+
3
+ module CiscoSpark
4
+ class Person
5
+ include Model
6
+ resource 'people'
7
+
8
+ attributes(
9
+ id: DataCaster::String,
10
+ emails: DataCaster::Array,
11
+ display_name: DataCaster::String,
12
+ avatar: DataCaster::String,
13
+ created: DataCaster::DateTime,
14
+ )
15
+
16
+ end
17
+ end
@@ -0,0 +1,21 @@
1
+ require "cisco_spark/model"
2
+
3
+ module CiscoSpark
4
+ class Room
5
+ include Model
6
+ resource 'rooms'
7
+
8
+ attributes(
9
+ id: DataCaster::String,
10
+ title: DataCaster::String,
11
+ created: DataCaster::DateTime,
12
+ last_activity: DataCaster::DateTime,
13
+ is_locked: DataCaster::Boolean,
14
+ sip_address: DataCaster::String
15
+ )
16
+
17
+ def messages
18
+ CiscoSpark::Message.fetch_all(room_id: id)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ module Utils
2
+ extend self
3
+
4
+ def camelize(obj)
5
+ obj.to_s.split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module CiscoSpark
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cisco_spark
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Nick Maher
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-09 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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: dotenv
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
+ description:
84
+ email:
85
+ - nickpmaher@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".coveralls.yml"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".ruby-version"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - cisco_spark.gemspec
102
+ - lib/cisco_spark.rb
103
+ - lib/cisco_spark/api.rb
104
+ - lib/cisco_spark/configuration.rb
105
+ - lib/cisco_spark/data_caster.rb
106
+ - lib/cisco_spark/errors.rb
107
+ - lib/cisco_spark/model.rb
108
+ - lib/cisco_spark/models/membership.rb
109
+ - lib/cisco_spark/models/message.rb
110
+ - lib/cisco_spark/models/person.rb
111
+ - lib/cisco_spark/models/room.rb
112
+ - lib/cisco_spark/utils.rb
113
+ - lib/cisco_spark/version.rb
114
+ homepage: https://github.com/NGMarmaduke/cisco_spark-ruby
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 1.9.2
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.5.1
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: 'Ruby client for Cisco Spark: https://developer.ciscospark.com'
138
+ test_files: []