stackreduce 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4b1ab333cc966d1cbb14049a2f8b3f28736d266
4
- data.tar.gz: ecaf8ffe8ee054a7ad07f7fa5f754abb4ef8ac04
3
+ metadata.gz: caff3906b88f3558b9d17e19b65f146ccb734e83
4
+ data.tar.gz: df221397de65bee887e7034954051c4b51892eca
5
5
  SHA512:
6
- metadata.gz: b6c142ebae519abd08879f5dbf9299494a215d1f2076be1709951d8b2185a1a64c11bfee717b22824b61156bf5d03ea77de72ca2400d746d1610b2ff77f104d8
7
- data.tar.gz: c9265eadea26652c0d6fb90a1802bd438b55e23ebb7f243c5fdc70807ad49df12ae0dbe7e16dd670bc1d19a4031f32f94319934e890d0397c8ed34cebfc2359d
6
+ metadata.gz: 4afbd26e3b6c8b0993a1bf777f8694cdb6a776d85549a89b4c19d3f7f4fe447ec9b24a071a567ef5b2775dbc73682ede2344a18211ffa443bdfadd2e913c6c18
7
+ data.tar.gz: 968e38d3ce61dfb0b4d9da9736d5bc7a7aec32b2eb44c79e7bda8eedb4657f67280c553963bb1e54c1e9e9e7b7844d4b46ccac831773a0cee33c2506c8cf3af8
data/README.md CHANGED
@@ -1,10 +1,26 @@
1
- # Stackreduce
1
+ # Stackreduce API Wrapper
2
2
 
3
- TODO: Write a gem description
4
3
 
5
- ## Installation
6
4
 
7
- Add this line to your application's Gemfile:
5
+
6
+ Stackreduce gem its a Rails API Wrapper for [Stackreduce.com](http://www.stackreduce.com/)
7
+ A simple solutions for pushing your data from your rails app
8
+
9
+ [![Code Climate](https://codeclimate.com/github/stackreduce/stackreduce.png)](https://codeclimate.com/github/stackreduce/stackreduce)
10
+ [![Gem Version](https://badge.fury.io/rb/stackreduce.png)](http://badge.fury.io/rb/stackreduce)
11
+
12
+ ### RDocs
13
+
14
+ You can view the Stackreduce documentation in RDoc format here:
15
+
16
+ http://rubydoc.info/github/stackreduce/stackreduce/master/frames
17
+
18
+
19
+ ### Issue tracker
20
+ https://github.com/stackreduce/stackreduce/issues
21
+
22
+ ## Getting started
23
+ Add it to your Gemfile:
8
24
 
9
25
  gem 'stackreduce'
10
26
 
@@ -16,10 +32,54 @@ Or install it yourself as:
16
32
 
17
33
  $ gem install stackreduce
18
34
 
35
+ ## Create a config file
36
+ From console run the generator:
37
+
38
+ $ rails g stackreduce:config
39
+
40
+ It will create a config file under your
41
+
42
+ config/initializers/stackreduce_config.rb
43
+
44
+ Edit your config file and add your applications id and token:
45
+
46
+ Stackreduce.configure do |config|
47
+ config.app_id = "YOUR_APP_ID"
48
+ config.token = "YOUR_APP_TOKEN"
49
+ end
50
+
19
51
  ## Usage
52
+ Push a new stack:
20
53
 
21
- TODO: Write usage instructions here
54
+ Stackreduce.push User.all
22
55
 
56
+ or create a stack with a name:
57
+
58
+ Stackreduce.push User.all, :stack => "My awesome stack"
59
+
60
+
61
+
62
+ ## Seed en example Stack
63
+ Push a new demo stack:
64
+
65
+ Will generate an demo stack with users named "My Users Stack"
66
+
67
+ Stackreduce.seed :users => "My Users Stack"
68
+
69
+ Will generate an demo stack with users named "My Products Stack"
70
+
71
+ Stackreduce.seed :products => "My Products Stack"
72
+
73
+ Defaults: Will generate an demo stack with users
74
+
75
+ Stackreduce.seed
76
+
77
+
78
+
79
+ ## Tested with
80
+ Rails 4.0.0
81
+ ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]
82
+
23
83
  ## Contributing
24
84
 
25
85
  1. Fork it
@@ -27,3 +87,10 @@ TODO: Write usage instructions here
27
87
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
88
  4. Push to the branch (`git push origin my-new-feature`)
29
89
  5. Create new Pull Request
90
+
91
+ ## License
92
+
93
+ Released under the MIT license
94
+ see the file License.
95
+
96
+ Created by Yannis Kolovos (https://github.com/msroot)
@@ -0,0 +1,16 @@
1
+ module Stackreduce
2
+ module Generators
3
+ class ConfigGenerator < Rails::Generators::Base
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
+
6
+ desc <<DESC
7
+ Description:
8
+ Copies Stackreduce configuration file to your application's initializer directory.
9
+ DESC
10
+
11
+ def copy_config_file
12
+ template 'stackreduce_config.rb', 'config/initializers/stackreduce_config.rb'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ Stackreduce.configure do |config|
3
+ # Your applications id. Where you save the stacks.
4
+ # This can be found under applications page
5
+ config.app_id = ""
6
+ # Your applications secret token.
7
+ # This can be found under applications page
8
+ config.token = ""
9
+ end
@@ -1,5 +1,67 @@
1
- require "stackreduce/version"
1
+ require 'active_support'
2
+ require 'active_support/configurable'
3
+ require 'active_support/inflector'
2
4
 
3
5
  module Stackreduce
4
- # Your code goes here...
5
- end
6
+ extend ActiveSupport::Autoload
7
+
8
+ # Use ActiveSupport::Autoload for better performance
9
+ # autoload all required classes
10
+ autoload :Version
11
+ autoload :Exceptions
12
+ autoload :Stack
13
+ autoload :Seed
14
+
15
+ # User from rails initializer
16
+ # ==== Examples
17
+ # Stackreduce.configure do |config|
18
+ # config.token = "my_very_big_token"
19
+ # config.app_id = "my_applications_id"
20
+ # end
21
+ def self.configure
22
+ yield self
23
+ end
24
+
25
+ # Applications token
26
+ # find in applications settings.
27
+ # we use it for saving the stack
28
+ # ==== Examples
29
+ # Stackreduce.token
30
+ include ActiveSupport::Configurable
31
+ config_accessor :app_id, :token
32
+
33
+ # Parses the given array to json
34
+ # ==== Arguments
35
+ # * +data+ - Array
36
+ # ==== Examples
37
+ # Stackreduce.parse Client.includes(:address).limit(10)
38
+ # Stackreduce.parse User.all
39
+ def self.parse(data)
40
+ Stackreduce::Stack.parse(data)
41
+ end
42
+
43
+ # Main api call method
44
+ # ==== Arguments
45
+ # * +data+ - Array
46
+ # ==== Examples
47
+ # Stackreduce.push Client.includes(:address).limit(10)
48
+ # Stackreduce.push User.all
49
+ # Stackreduce.push User.all, :stack => "My awesome stack"
50
+ def self.push(data=nil, options = {})
51
+ Stackreduce::Stack.push(data, options)
52
+ end
53
+
54
+
55
+ # Seeding demo stacks
56
+ # ==== Arguments
57
+ # * +:users+ - String
58
+ # * +:products+ - String
59
+ # ==== Examples
60
+ # Stackreduce.seed
61
+ # Stackreduce.seed :users => "My Users Stack"
62
+ # Stackreduce.seed :products => "My Products Stack"
63
+ def self.seed(options = {})
64
+ Stackreduce::Seed.seed(options)
65
+ end
66
+
67
+ end
@@ -0,0 +1,10 @@
1
+ module Stackreduce
2
+
3
+ class StackreduceException < Exception
4
+ end
5
+
6
+ def self.exception e
7
+ raise StackreduceException.new e
8
+ end
9
+
10
+ end
@@ -0,0 +1,62 @@
1
+ require 'faker'
2
+ require 'stackreduce/exceptions'
3
+ require 'active_model'
4
+
5
+ module Stackreduce
6
+ class Seed
7
+
8
+ class Seeduser
9
+ include ActiveModel::Model
10
+ attr_accessor :name, :city, :email, :country, :state
11
+ end
12
+
13
+ class Seedproduct
14
+ include ActiveModel::Model
15
+ attr_accessor :name, :color, :duns_number, :company_name, :department
16
+ end
17
+
18
+ def self.seed_users(stack)
19
+ users = []
20
+ 50.times do
21
+ users << Seeduser.new(
22
+ :name=>Faker::Name.name,
23
+ :city=>Faker::Address.city,
24
+ :country=>Faker::Address.country,
25
+ :state=>Faker::Address.state,
26
+ :email=>Faker::Internet.email
27
+ )
28
+ end
29
+ Stackreduce.push(users, :stack=> stack)
30
+ end
31
+
32
+
33
+
34
+ def self.seed_products(stack)
35
+ products = []
36
+ 50.times do
37
+ products << Seedproduct.new(
38
+ :name=>Faker::Commerce.product_name,
39
+ :color=>Faker::Commerce.color,
40
+ :duns_number=>Faker::Company.duns_number,
41
+ :company_name=>Faker::Company.name,
42
+ :department=>Faker::Commerce.department
43
+ )
44
+ end
45
+ Stackreduce.push(products, :stack=> stack)
46
+ end
47
+
48
+
49
+
50
+ def self.seed(options)
51
+ if options[:users]
52
+ seed_users(options[:users])
53
+ elsif options[:products]
54
+ seed_products(options[:products])
55
+ else
56
+ seed_users("SEEDED: Demo Users Stack")
57
+ end
58
+ end
59
+
60
+
61
+ end
62
+ end
@@ -0,0 +1,53 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'stackreduce/exceptions'
4
+
5
+ module Stackreduce
6
+
7
+ class Stack
8
+
9
+ END_POINT_URL = "http://www.stackreduce.com/api/v1/stacks.json"
10
+
11
+ def self.config_is_valid? #:nodoc:
12
+ !(Stackreduce.token.blank? or Stackreduce.app_id.blank?)
13
+ end
14
+
15
+
16
+ def self.validate_config! #:nodoc:
17
+ Stackreduce.exception("Config is not valid: #{Stackreduce.config.inspect}") unless config_is_valid?
18
+ end
19
+
20
+
21
+ def self.parse(data_array)
22
+ data = nil
23
+ begin
24
+ data = ActiveSupport::JSON.encode(data_array)
25
+ rescue e
26
+ Stackreduce.exception e
27
+ end
28
+ data
29
+ end
30
+
31
+
32
+ def self.push(data, options)
33
+ validate_config!
34
+ data = parse(data)
35
+ # we use :stack for argument here but rails expecting :name
36
+ stack = options[:stack] ||= nil
37
+
38
+ params = {'token' => Stackreduce.token,'app_id' => Stackreduce.app_id,'stack_data' => data}
39
+ params.merge!('name' => stack) unless stack.nil?
40
+
41
+ uri = URI(END_POINT_URL)
42
+ res = Net::HTTP.post_form(uri, params)
43
+
44
+ handle_response res
45
+ end
46
+
47
+
48
+ def self.handle_response res #:nodoc:
49
+ res.code == "200" ? ActiveSupport::JSON.decode(res.body) : Stackreduce.exception("Response: #{res.inspect}")
50
+ end
51
+
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module Stackreduce
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2".freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackreduce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
- - John Kolovos
7
+ - Yannis Kolovos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-04 00:00:00.000000000 Z
11
+ date: 2013-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
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: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faker
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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'
13
69
  - !ruby/object:Gem::Dependency
14
70
  name: bundler
15
71
  requirement: !ruby/object:Gem::Requirement
@@ -38,23 +94,50 @@ dependencies:
38
94
  - - '>='
39
95
  - !ruby/object:Gem::Version
40
96
  version: '0'
41
- description: Write a gem description
97
+ - !ruby/object:Gem::Dependency
98
+ name: cucumber
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: aruba
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Stackreduce.com API Wrapper
42
126
  email:
43
127
  - yannis.kolovos@gmail.com
44
128
  executables: []
45
129
  extensions: []
46
130
  extra_rdoc_files: []
47
131
  files:
48
- - .DS_Store
49
- - .gitignore
50
- - Gemfile
51
- - LICENSE.txt
52
132
  - README.md
53
- - Rakefile
54
- - lib/stackreduce.rb
133
+ - lib/generators/stackreduce/config_generator.rb
134
+ - lib/generators/stackreduce/templates/stackreduce_config.rb
135
+ - lib/stackreduce/exceptions.rb
136
+ - lib/stackreduce/seed.rb
137
+ - lib/stackreduce/stack.rb
55
138
  - lib/stackreduce/version.rb
56
- - stackreduce.gemspec
57
- homepage: ''
139
+ - lib/stackreduce.rb
140
+ homepage: http://www.stackreduce.com
58
141
  licenses:
59
142
  - MIT
60
143
  metadata: {}
@@ -66,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
149
  requirements:
67
150
  - - '>='
68
151
  - !ruby/object:Gem::Version
69
- version: '0'
152
+ version: 1.9.3
70
153
  required_rubygems_version: !ruby/object:Gem::Requirement
71
154
  requirements:
72
155
  - - '>='
@@ -77,5 +160,5 @@ rubyforge_project:
77
160
  rubygems_version: 2.0.3
78
161
  signing_key:
79
162
  specification_version: 4
80
- summary: Write a gem summary
163
+ summary: Stackreduce gem its a Rails API Wrapper for Stackreduce.com
81
164
  test_files: []
data/.DS_Store DELETED
Binary file
data/.gitignore DELETED
@@ -1,17 +0,0 @@
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
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in stackreduce.gemspec
4
- gemspec
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 John Kolovos
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/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
@@ -1,23 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'stackreduce/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "stackreduce"
8
- spec.version = Stackreduce::VERSION
9
- spec.authors = ["John Kolovos"]
10
- spec.email = ["yannis.kolovos@gmail.com"]
11
- spec.description = %q{Write a gem description}
12
- spec.summary = %q{Write a gem summary}
13
- spec.homepage = ""
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
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.3"
22
- spec.add_development_dependency "rake"
23
- end