json_slide 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: 9700e762e7ae7ac9efc34366181d4d7c6fe5584a
4
+ data.tar.gz: 174dfdb76a334213206add483b0f4951457a05d0
5
+ SHA512:
6
+ metadata.gz: 34072268d629a98f4c13c968b059d4234e6945990452fd228ce3d07c7c106958eacb8a30d46296ac2a5081914dbb5e226423c6287252ded845a704ff1419b32b
7
+ data.tar.gz: 00943ffe278dffcda57ddd946d02dfcdfe005fb5a8f6a71428fa5d6a7c742753aa68c8ed07187956e3bd2ecc45ffff50a56127b6de04205127f97990ca47d917
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in json_slide.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Asit Moharna
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # JsonSlide
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'json_slide'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install json_slide
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/json_slide/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'json_slide/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "json_slide"
8
+ spec.version = JsonSlide::VERSION
9
+ spec.authors = ["Asit Moharna"]
10
+ spec.email = ["asitkmoharna@gmail.com"]
11
+ spec.summary = %q{Creates opinionated slides from json.}
12
+ spec.description = %q{Creates opinionated slides from json. An experiment!}
13
+ spec.homepage = ""
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_dependency "rest-client"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
data/lib/json_slide.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "json_slide/version"
2
+ require "json_slide/parser"
3
+
4
+ module JsonSlide
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,44 @@
1
+ require 'json'
2
+ require 'rest_client'
3
+
4
+ module JsonSlide
5
+ #== Parser
6
+ class Parser
7
+ # Returns a ruby hash by parsing the json
8
+ #
9
+ # === Notes
10
+ # it needs a json string or json file with file path or json file url
11
+ #
12
+ # === Examples
13
+ # parser = JsonSlide::Parser.parse("{\"slide1\":{},\"slide2\":{}}")
14
+ # parser = JsonSlide::Parser.parse('path/to/my/awesome/file.json')
15
+ # parser = JsonSlide::Parser.parse('http://awesome_url.json')
16
+ #
17
+ # === Parameters
18
+ # * json_input: String containing the json string / json file path / json url
19
+ #
20
+ # === Returns
21
+ # * Symbolized ruby hash by parsing the json
22
+ class << self
23
+ def parse(json_input)
24
+ begin
25
+ json = if(json_input =~ URI::regexp)
26
+ RestClient.get(json_input)
27
+ elsif ( !(json_input).match(/\.json$/i).nil? && File.exist?(json_input) && File.file?(json_input) )
28
+ File.read(json_input)
29
+ else
30
+ json_input
31
+ end
32
+ JSON.parse(json, { symbolize_names: true })
33
+ rescue JSON::ParserError
34
+ raise "Invalid JSON Format!! Please enter a valid json string or json file with path or json file url."
35
+ rescue URI::InvalidURIError
36
+ raise "Invalid JSON url!! Please enter a valid json string or json file with path or json file url."
37
+ rescue => e
38
+ raise e.message
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module JsonSlide
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'json_slide/parser'
3
+
4
+ describe JsonSlide::Parser do
5
+
6
+ describe '.parse' do
7
+
8
+ it 'raises argument error if no argument is provided' do
9
+ expect { JsonSlide::Parser.parse }.to raise_error(ArgumentError)
10
+ end
11
+
12
+ context 'json string is given as argument' do
13
+ context 'and its valid' do
14
+ it 'parses the json string' do
15
+ expect(JsonSlide::Parser.parse("{\"slide1\":{},\"slide2\":{}}")).to eq({slide1: {}, slide2: {}})
16
+ end
17
+ end
18
+ context 'and its invalid' do
19
+ it 'raises Invalid json error' do
20
+ expect { JsonSlide::Parser.parse("invalid_json") }.to raise_error("Invalid JSON Format!! Please enter a valid json string or json file with path or json file url.")
21
+ end
22
+ end
23
+ end
24
+
25
+ context 'json file is given as argument' do
26
+ context 'and its valid' do
27
+ it "parses the json file" do
28
+ allow(File).to receive(:exist?).with('test.json').and_return(true)
29
+ allow(File).to receive(:file?).with('test.json').and_return(true)
30
+ expect(File).to receive(:read).with('test.json').and_return("{\"slide1\":{},\"slide2\":{}}")
31
+ expect(JsonSlide::Parser.parse("test.json")).to eq({slide1: {}, slide2: {}})
32
+ end
33
+ end
34
+ context 'and its invalid' do
35
+ it 'raises Invalid json error' do
36
+ expect { JsonSlide::Parser.parse("invalid_json_file.json") }.to raise_error("Invalid JSON Format!! Please enter a valid json string or json file with path or json file url.")
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'json url is given as argument' do
42
+ context 'and its valid' do
43
+ it "parses the json content in the specified url" do
44
+ allow(RestClient).to receive(:get).with('http://my_awesome_slides.json').and_return("{\"slide1\":{},\"slide2\":{}}")
45
+ expect(JsonSlide::Parser.parse("http://my_awesome_slides.json")).to eq({slide1: {}, slide2: {}})
46
+ end
47
+ end
48
+ context 'and its invalid' do
49
+ it 'raises Invalid json error' do
50
+ expect { JsonSlide::Parser.parse("http://do_not_exist/some.json") }.to raise_error("Invalid JSON url!! Please enter a valid json string or json file with path or json file url.")
51
+ end
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,78 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # The settings below are suggested to provide a good initial experience
19
+ # with RSpec, but feel free to customize to your heart's content.
20
+ =begin
21
+ # These two settings work together to allow you to limit a spec run
22
+ # to individual examples or groups you care about by tagging them with
23
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
+ # get run.
25
+ config.filter_run :focus
26
+ config.run_all_when_everything_filtered = true
27
+
28
+ # Many RSpec users commonly either run the entire suite or an individual
29
+ # file, and it's useful to allow more verbose output when running an
30
+ # individual spec file.
31
+ if config.files_to_run.one?
32
+ # Use the documentation formatter for detailed output,
33
+ # unless a formatter has already been configured
34
+ # (e.g. via a command-line flag).
35
+ config.default_formatter = 'doc'
36
+ end
37
+
38
+ # Print the 10 slowest examples and example groups at the
39
+ # end of the spec run, to help surface which specs are running
40
+ # particularly slow.
41
+ config.profile_examples = 10
42
+
43
+ # Run specs in random order to surface order dependencies. If you find an
44
+ # order dependency and want to debug it, you can fix the order by providing
45
+ # the seed, which is printed after each run.
46
+ # --seed 1234
47
+ config.order = :random
48
+
49
+ # Seed global randomization in this process using the `--seed` CLI option.
50
+ # Setting this allows you to use `--seed` to deterministically reproduce
51
+ # test failures related to randomization by passing the same `--seed` value
52
+ # as the one that triggered the failure.
53
+ Kernel.srand config.seed
54
+
55
+ # rspec-expectations config goes here. You can use an alternate
56
+ # assertion/expectation library such as wrong or the stdlib/minitest
57
+ # assertions if you prefer.
58
+ config.expect_with :rspec do |expectations|
59
+ # Enable only the newer, non-monkey-patching expect syntax.
60
+ # For more details, see:
61
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
+ expectations.syntax = :expect
63
+ end
64
+
65
+ # rspec-mocks config goes here. You can use an alternate test double
66
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
67
+ config.mock_with :rspec do |mocks|
68
+ # Enable only the newer, non-monkey-patching expect syntax.
69
+ # For more details, see:
70
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ mocks.syntax = :expect
72
+
73
+ # Prevents you from mocking or stubbing a method that does not exist on
74
+ # a real object. This is generally recommended.
75
+ mocks.verify_partial_doubles = true
76
+ end
77
+ =end
78
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json_slide
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Asit Moharna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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: rspec
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
+ description: Creates opinionated slides from json. An experiment!
70
+ email:
71
+ - asitkmoharna@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - json_slide.gemspec
83
+ - lib/json_slide.rb
84
+ - lib/json_slide/parser.rb
85
+ - lib/json_slide/version.rb
86
+ - spec/json_slide/parser_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.1.10
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Creates opinionated slides from json.
112
+ test_files:
113
+ - spec/json_slide/parser_spec.rb
114
+ - spec/spec_helper.rb
115
+ has_rdoc: