bluemix_datacache 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: 57e0f5cff668198d1f6bd68e9f114efbdcc80f4b
4
+ data.tar.gz: 72163eeafe77d5f8f21bb0ef6d96d7fc3a95532c
5
+ SHA512:
6
+ metadata.gz: 6803d20c91acb7ed42911121b2a9cfa765299b26b9c274dac562970b25a7a0ceb35b369dfadd7d54d899e6e998b9505b713adade925ddb73cbcf74cc6eb101d0
7
+ data.tar.gz: 2da07820653b88ef65c0819e5e1cd4eb2012b5412a55e2e0f7a595821888e20fbc816a173cb753757bcf27b33130940c8ef5dd2dc00daf3052b565cf0dea99da
data/.gitignore ADDED
@@ -0,0 +1,38 @@
1
+ # Created by https://www.gitignore.io
2
+
3
+ ### Ruby ###
4
+ *.gem
5
+ *.rbc
6
+ /.config
7
+ /coverage/
8
+ /InstalledFiles
9
+ /pkg/
10
+ /spec/reports/
11
+ /test/tmp/
12
+ /test/version_tmp/
13
+ /tmp/
14
+
15
+ ## Specific to RubyMotion:
16
+ .dat*
17
+ .repl_history
18
+ build/
19
+
20
+ ## Documentation cache and generated files:
21
+ /.yardoc/
22
+ /_yardoc/
23
+ /doc/
24
+ /rdoc/
25
+
26
+ ## Environment normalisation:
27
+ /.bundle/
28
+ /vendor/bundle
29
+ /lib/bundler/man/
30
+
31
+ # for a library or gem, you might want to ignore these files since the code is
32
+ # intended to run in multiple environments; otherwise, check them in:
33
+ # Gemfile.lock
34
+ # .ruby-version
35
+ # .ruby-gemset
36
+
37
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
38
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bluemix_datacache.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bluemix_datacache (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.4.2)
11
+ rspec (3.3.0)
12
+ rspec-core (~> 3.3.0)
13
+ rspec-expectations (~> 3.3.0)
14
+ rspec-mocks (~> 3.3.0)
15
+ rspec-core (3.3.1)
16
+ rspec-support (~> 3.3.0)
17
+ rspec-expectations (3.3.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.3.0)
20
+ rspec-mocks (3.3.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.3.0)
23
+ rspec-support (3.3.0)
24
+
25
+ PLATFORMS
26
+ x64-mingw32
27
+
28
+ DEPENDENCIES
29
+ bluemix_datacache!
30
+ bundler (~> 1.10)
31
+ rake (~> 10.0)
32
+ rspec
33
+
34
+ BUNDLED WITH
35
+ 1.10.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Yusuke Mukai
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,38 @@
1
+ # Bluemix Data cache gem
2
+
3
+
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bluemix_datacache'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install bluemix_datacache
20
+
21
+ ## Usage
22
+
23
+
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mukopikmin/bluemix-datacache-gem.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
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 "bluemix_datacache"
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,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bluemix_datacache/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bluemix_datacache"
8
+ spec.version = BluemixDatacache::VERSION
9
+ spec.authors = ["Yusuke Mukai"]
10
+ spec.email = ["opposite0302@gmail.com"]
11
+
12
+ spec.summary = "Bluemix Data cache plugin"
13
+ spec.description = "Using Bluemix Data cache service from ruby."
14
+ spec.homepage = "https://github.com/mukopikmin/bluemix-datacache-gem"
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
+ end
@@ -0,0 +1,73 @@
1
+ require "bluemix_datacache/version"
2
+ require 'json'
3
+ require 'base64'
4
+ require 'uri'
5
+ require 'net/http'
6
+
7
+ module BluemixDatacache
8
+ class Client
9
+
10
+ def initialize(map)
11
+ begin
12
+ credential = JSON.parse(ENV["VCAP_SERVICES"])["DataCache-1.0"][0]["credentials"]
13
+ auth = "#{credential['username']}:#{credential['password']}"
14
+ @api = credential['restResource']
15
+ @auth = "Basic #{Base64.strict_encode64(auth)}"
16
+ @map = map
17
+ rescue
18
+ p "Could not identify VCAP_SERVICES"
19
+ end
20
+ end
21
+
22
+ def insert(key, value, content_type)
23
+ begin
24
+ uri = URI.parse("#{@api}/#{URI.escape(@map)}/#{URI.escape(key)}")
25
+ Net::HTTP.start(uri.host, uri.port) do |http|
26
+ request = Net::HTTP::Post.new(uri.path)
27
+ request["Content-type"] = content_type
28
+ request["Authorization"] = @auth
29
+ request["rejectUnauthorized"] = false
30
+ request["agent"] = false
31
+ request.body = value
32
+ response = http.request(request)
33
+ return response.code.to_i
34
+ end
35
+ rescue
36
+ return nil
37
+ end
38
+ end
39
+
40
+ def select(key)
41
+ begin
42
+ uri = URI.parse("#{@api}/#{URI.escape(@map)}/#{URI.escape(key)}")
43
+ Net::HTTP.start(uri.host, uri.port) do |http|
44
+ request = Net::HTTP::Get.new(uri.path)
45
+ request["Authorization"] = @auth
46
+ request["rejectUnauthorized"] = false
47
+ request["agent"] = false
48
+ response = http.request(request)
49
+ return {:key => key, :value => response.body, :type => response['content-type']}
50
+ end
51
+ rescue
52
+ return nil
53
+ end
54
+ end
55
+
56
+ def delete(key)
57
+ begin
58
+ uri = URI.parse("#{@api}/#{URI.escape(@map)}/#{URI.escape(key)}")
59
+ Net::HTTP.start(uri.host, uri.port) do |http|
60
+ request = Net::HTTP::Delete.new(uri.path)
61
+ request["Authorization"] = @auth
62
+ request["rejectUnauthorized"] = false
63
+ request["agent"] = false
64
+ response = http.request(request)
65
+ return true
66
+ end
67
+ rescue
68
+ return false
69
+ end
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module BluemixDatacache
2
+ VERSION = "0.1.0"
3
+ end
data/test.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'bluemix_datacache'
2
+
3
+ b = BluemixDatacache.new("aa")
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bluemix_datacache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yusuke Mukai
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-28 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
+ description: Using Bluemix Data cache service from ruby.
56
+ email:
57
+ - opposite0302@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - bluemix_datacache.gemspec
73
+ - lib/bluemix_datacache.rb
74
+ - lib/bluemix_datacache/version.rb
75
+ - test.rb
76
+ homepage: https://github.com/mukopikmin/bluemix-datacache-gem
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.8
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Bluemix Data cache plugin
100
+ test_files: []
101
+ has_rdoc: