jaspion-kilza 1.0.8

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: 5e7abc9dfe396f9eef474cf11b374b791d3750b1
4
+ data.tar.gz: 60814db03aaf45197f5f36c70bba4b54882883fc
5
+ SHA512:
6
+ metadata.gz: 0da939967226bd29ee3b9ab272f596ee07faf252a8c6b1dd1cd199b34ddb4d966452b7bc4817a65599aaef40f6e75a6dd8eb2917db9edefbe463e717f3089397
7
+ data.tar.gz: f9e4469139c16cea2fc524709f36c304b2d4534cb56e982fe4ab7a52961c0e0d9d645905bd93514049b81bc253e34af985d2c24ed0da10955b0702acd27be105
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
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/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
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 kilza.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Toshiro Sugii
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,180 @@
1
+ # Jaspion Kilza
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/kilza.svg)](https://badge.fury.io/rb/kilza)
4
+
5
+ [![Build Status](https://travis-ci.org/Jaspion/Kilza.svg?branch=master)](https://travis-ci.org/Jaspion/Kilza)
6
+
7
+ [![Coverage Status](https://coveralls.io/repos/github/Jaspion/Kilza/badge.svg?branch=master)](https://coveralls.io/github/Jaspion/Kilza?branch=master)
8
+
9
+ [![Inline docs](http://inch-ci.org/github/jaspion/kilza.svg?branch=master)](http://inch-ci.org/github/jaspion/kilza)
10
+
11
+ Ruby gem that can convert JSON strings in Objects.
12
+
13
+ It supports Objective-C and Java classes. Contribuition would be appreciate.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'jaspion-kilza'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install jaspion-kilza
30
+
31
+ ## Binary
32
+
33
+ Just call:
34
+
35
+ kilza
36
+
37
+ And the Kilza will guide you.
38
+
39
+ ## Usage in code
40
+
41
+ Just
42
+
43
+ require 'jaspion/kilza'
44
+
45
+ And then
46
+
47
+ ```
48
+ json_string = "..."
49
+
50
+ java = Jaspion::Kilza::Java.new(json_string)
51
+ java.classes("MyBaseClass").each { |c|
52
+ c.sources.each{ |s|
53
+ File.write(File.join("my/target/path", s.file_name), s.source)
54
+ }
55
+ }
56
+ ```
57
+
58
+ ## Example
59
+
60
+ Let's see in action.
61
+ Suppose our variable **json_string** have the following string:
62
+
63
+ ```
64
+ {
65
+
66
+ "Code": ​110,
67
+ "Message": ""
68
+
69
+ }
70
+ ```
71
+
72
+ Calling the code above:
73
+
74
+ ```
75
+ java = Jaspion::Kilza::Java.new(json_string)
76
+ java.classes("MyBaseClass").each { |c|
77
+ c.sources.each{ |s|
78
+ File.write(File.join("my/target/path", s.file_name), s.source)
79
+ }
80
+ }
81
+ ```
82
+
83
+ Will generate:
84
+
85
+ ```
86
+ package ;
87
+
88
+ import org.json.*;
89
+ import java.io.Serializable;
90
+
91
+ import com.google.gson.Gson;
92
+ import com.google.gson.GsonBuilder;
93
+ import com.google.gson.annotations.SerializedName;
94
+ import com.google.gson.annotations.Expose;
95
+
96
+ public class Mybaseclass implements Serializable
97
+ {
98
+ private static final String FIELD_CODE = "Code";
99
+ private static final String FIELD_MESSAGE = "Message";
100
+
101
+ @Expose
102
+ @SerializedName(FIELD_CODE)
103
+ private Long code;
104
+ @Expose
105
+ @SerializedName(FIELD_MESSAGE)
106
+ private String message;
107
+
108
+ public Mybaseclass() {
109
+
110
+ }
111
+
112
+ public Mybaseclass(JSONObject jsonObject) {
113
+ parseObject(jsonObject);
114
+ }
115
+
116
+ public Mybaseclass(String jsonString) {
117
+ try {
118
+ parseString(jsonString);
119
+ } catch (JSONException e) {
120
+ e.printStackTrace();
121
+ }
122
+ }
123
+
124
+ protected void parseString(String jsonString) throws JSONException {
125
+ JSONObject jsonObject = new JSONObject(jsonString);
126
+ parseObject(jsonObject);
127
+ }
128
+
129
+ protected void parseObject(JSONObject object)
130
+ {
131
+ this.code = object.optLong(FIELD_CODE);
132
+ this.message = object.optString(FIELD_MESSAGE);
133
+ }
134
+
135
+ public void setCode(Long value) {
136
+ this.code = value;
137
+ }
138
+
139
+ public Long getCode() {
140
+ return this.code;
141
+ }
142
+
143
+ public void setMessage(String value) {
144
+ this.message = value;
145
+ }
146
+
147
+ public String getMessage() {
148
+ return this.message;
149
+ }
150
+
151
+ @Override
152
+ public boolean equals(Object obj) {
153
+ if (obj instanceof Mybaseclass) {
154
+ return ((Mybaseclass) obj).getCode().equals(code) &&
155
+ ((Mybaseclass) obj).getMessage().equals(message) ;
156
+ }
157
+ return false;
158
+ }
159
+ @Override
160
+ public int hashCode(){
161
+ return (code.hashCode() +
162
+ message.hashCode());
163
+ }
164
+
165
+ @Override
166
+ public String toString() {
167
+ Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
168
+ return gson.toJson(this);
169
+ }
170
+ }
171
+ ```
172
+
173
+ ## Contributing
174
+
175
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jaspion/kilza. 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.
176
+
177
+
178
+ ## License
179
+
180
+ 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 'jaspion/kilza'
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/kilza ADDED
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'jaspion/kilza'
5
+ require 'pastel'
6
+ require 'tty'
7
+ require 'tty-prompt'
8
+ require 'tty-spinner'
9
+ require 'net/http'
10
+ require 'uri'
11
+
12
+ def read_url(url)
13
+ Net::HTTP.get(URI.parse(url))
14
+ end
15
+
16
+ module TTY
17
+ class Prompt
18
+ class List
19
+ def enum(value)
20
+ @enum = value
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ class KilzaApplication
27
+
28
+ OBJC = 1
29
+ JAVA = 2
30
+
31
+ def initialize
32
+ @pastel = Pastel.new
33
+ @prompt = TTY::Prompt.new
34
+ @spinner = TTY::Spinner.new
35
+
36
+ @done = false
37
+ end
38
+
39
+ def get_lang
40
+ action = @prompt.select(@pastel.bold('Target programming language?')) do |menu|
41
+ menu.default 1
42
+ menu.enum '.'
43
+
44
+ menu.choice 'Objective-C', OBJC
45
+ menu.choice 'Java', JAVA
46
+ end
47
+ action
48
+ end
49
+
50
+ def get_json
51
+ action = @prompt.select(@pastel.bold('Where is your JSON string content?')) do |menu|
52
+ menu.default 1
53
+ menu.enum '.'
54
+
55
+ menu.choice 'It\'s online. I have an URL.', 1
56
+ menu.choice 'It\'s offline. I have the file path.', 2
57
+ end
58
+
59
+ json_string = ''
60
+ if (action == 1)
61
+ url = @prompt.ask(@pastel.bold('Please, what is the URL? ')) do |q|
62
+ q.required true
63
+ end
64
+ @prompt.say(@pastel.bold('Ok. I\'ll try to get the content right now.'))
65
+ json_string = read_url(url)
66
+ else
67
+ file_path = File.expand_path(@prompt.ask(@pastel.bold('Please, what is the file path? '))) do |q|
68
+ q.required true
69
+ end
70
+ json_string = File.read(file_path.chomp)
71
+ end
72
+ json_string
73
+ end
74
+
75
+ def generate(lang, json_string, class_basename, target_path, class_package = '')
76
+ if (lang == OBJC)
77
+ objc = Jaspion::Kilza::Objc.new(json_string)
78
+ objc.classes(class_basename).each { |c|
79
+ c.sources.each{ |s|
80
+ File.write(File.join(target_path, s.file_name), s.source)
81
+ }
82
+ }
83
+ elsif (lang == JAVA)
84
+ java = Jaspion::Kilza::Java.new(json_string)
85
+ java.classes(class_basename).each { |c|
86
+ c.package = class_package
87
+ c.sources.each{ |s|
88
+ File.write(File.join(target_path, s.file_name), s.source)
89
+ }
90
+ }
91
+ end
92
+ end
93
+
94
+ def get_target_path
95
+ target_path = @prompt.ask(@pastel.bold('Master, where would you like to save? ')).chomp
96
+ File.expand_path(target_path)
97
+ end
98
+
99
+ def get_basename
100
+ @prompt.ask(@pastel.bold('Master, which name would like to call the first class? ')).chomp
101
+ end
102
+
103
+ def get_package
104
+ @prompt.ask(@pastel.bold('What is the target Java package? ')).chomp
105
+ end
106
+
107
+ def run
108
+ @prompt.say(@pastel.bold('Kilza - v' + Jaspion::Kilza::VERSION))
109
+ while (not @done)
110
+ action = @prompt.select(@pastel.bold('Master, what can I do for you?')) do |menu|
111
+ menu.default 1
112
+ menu.enum '.'
113
+
114
+ menu.choice 'I want some JSON objects.', 1
115
+ menu.choice 'Nothing.', 2
116
+ end
117
+ if action == 1
118
+ json_string = get_json
119
+ target_path = get_target_path
120
+ class_basename = get_basename
121
+ lang = get_lang
122
+
123
+ class_package = get_package if (lang == JAVA)
124
+
125
+ @prompt.say("\n")
126
+ @prompt.say(@pastel.bold('Target: ') + target_path)
127
+ @prompt.say(@pastel.bold('Base class name: ') + class_basename)
128
+ @prompt.say(@pastel.bold('Target language: ') + (lang == OBJC ? 'Objective-C' : 'Java'))
129
+ if not class_package.nil?
130
+ @prompt.say(@pastel.bold('Target package: ') + class_package)
131
+ end
132
+ ok = @prompt.yes?(@pastel.bold('Is that correct? '))
133
+ if ok.nil? or ok
134
+ generate(lang, json_string, class_basename, target_path, class_package)
135
+
136
+ @prompt.say(@pastel.bold('Kikera!'))
137
+ end
138
+ else
139
+ @done = true
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ KilzaApplication.new.run
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,45 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jaspion/kilza/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'jaspion-kilza'
8
+ spec.version = Jaspion::Kilza::VERSION
9
+ spec.authors = ['Toshiro Sugii']
10
+ spec.email = ['rtoshiro@printwtf.com']
11
+
12
+ spec.summary = 'Parses JSON and generates objects into other languages'
13
+ spec.description = %q{
14
+ Ruby gem that can convert JSON strings in Objects.
15
+ It supports Objective-C and Java classes. Contribuition would be appreciate.
16
+ }
17
+ spec.homepage = 'https://github.com/Jaspion/Kilza'
18
+ spec.license = 'MIT'
19
+
20
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
21
+ # delete this section to allow pushing this gem to any host.
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
+ else
25
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
26
+ end
27
+
28
+ spec.files= `git ls-files -z`.split("\x0").reject { |f|
29
+ f.match(%r{^(test|spec|features)/})
30
+ }
31
+ spec.bindir = 'bin'
32
+ spec.executables = ['kilza']
33
+ spec.require_paths = ['lib']
34
+
35
+ spec.add_development_dependency 'bundler', '~> 1.10'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'rspec'
38
+ spec.add_development_dependency 'minitest'
39
+ spec.add_development_dependency 'coveralls'
40
+
41
+ spec.add_dependency 'json'
42
+ spec.add_dependency 'erubis'
43
+ spec.add_dependency 'tty'
44
+ spec.add_dependency 'pastel'
45
+ end