ramen-rails 0.2.0 → 0.3.0

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: 938ed07e07491d1f7823571471a88e0a373dd34e
4
- data.tar.gz: 6c8dd0a2b1f1af76ff0ea56650322cc3542d88b3
3
+ metadata.gz: 3491acb100d8b4e8ce91ec01588a4c24baf58d55
4
+ data.tar.gz: bcc3d1257891f1de2f13d121c627f427f17d91ec
5
5
  SHA512:
6
- metadata.gz: 637a2e1e2da0a1f5d6820b4d0c9743570ec950b7fabf55ad347eada81da5df24e89473622f6b8450c732a91c09579e177a8e1aa44809bf2a0104914ff2df9e23
7
- data.tar.gz: 76591af04bd28c872dd6e18cddfde6e72a10debd9780cc5884e62d35d3484041d2b3069c17a4d71cd548457d62dfce4fb8b6b9ce7a6af03db3650e36be3f897f
6
+ metadata.gz: 11ea9d325e1ab2dc059898b3f52aa4eb9ac048dc3d750e61fdef188021480e5ffffe7471aa928c9cee353d8edaf9909f9fed7682a560fd4335bbc53c4fd915fa
7
+ data.tar.gz: 63abd2dcf73654e36eecef77ec2de17fb1fa66059620f45dbbf847b4b2a112b1420e54c47647db4bf9bd7b924aade9b0252869ae205f096031d16de6cb8fd915
data/CHANGELOG ADDED
@@ -0,0 +1,4 @@
1
+ CHANGELOG
2
+
3
+ Version 0.2.0: Add ability to pass in logged_in_url from ramenSettings
4
+ Version 0.3.0: Add RamenRails::Import for importing customers directly into Ramen from command line
data/README.md CHANGED
@@ -11,7 +11,7 @@ This gem will automatically inject the `ramen.js` script tag into pages.
11
11
  Add this to your Gemfile:
12
12
 
13
13
  ```
14
- gem "ramen-rails"
14
+ gem "ramen-rails", "~> 0.3.0"
15
15
  ```
16
16
 
17
17
  Then run:
@@ -10,7 +10,9 @@ module RamenRails
10
10
  :return_url,
11
11
  :return_label,
12
12
  :ramen_js_asset_uri,
13
- :custom_links
13
+ :custom_links,
14
+ :import_user_labels,
15
+ :import_user_value
14
16
 
15
17
  def ensure_not_lambda!(v)
16
18
  if v.lambda?
@@ -0,0 +1,77 @@
1
+ require 'uri'
2
+ require 'cgi'
3
+ require 'net/http'
4
+ module RamenRails
5
+ class Import
6
+ def self.all_users
7
+ User.all.each do |u|
8
+ new(user: u).import
9
+ end
10
+
11
+ nil
12
+ end
13
+
14
+ attr_accessor :user
15
+
16
+ def initialize(opts)
17
+ self.user = opts[:user]
18
+ end
19
+
20
+ def can_get_labels?
21
+ RamenRails.config.import_user_labels.present?
22
+ end
23
+
24
+ def can_get_value?
25
+ RamenRails.config.import_user_value.present?
26
+ end
27
+
28
+ def get_labels
29
+ user.
30
+ instance_eval(&RamenRails.config.import_user_labels)
31
+ end
32
+
33
+ def get_value
34
+ user.
35
+ instance_eval(&RamenRails.config.import_user_value)
36
+ end
37
+
38
+ def import
39
+ obj = {}
40
+ [:email, :name, :id].each do |attr|
41
+ obj[attr] = user.send(attr)
42
+ end
43
+
44
+ obj[:labels] = get_labels if can_get_labels?
45
+ obj[:value] = get_value if can_get_value?
46
+
47
+ if user.respond_to?(:created_at) && user.send(:created_at).present?
48
+ obj[:created_at] = user.send(:created_at).to_i
49
+ end
50
+
51
+ ts = Time.now.to_i
52
+
53
+ auth_hash = (Digest::SHA256.new << "#{obj[:email]}:#{obj[:id]}:#{obj[:name]}:#{ts}:#{RamenRails.config.organization_secret}").to_s
54
+
55
+ h = {
56
+ organization_id: RamenRails.config.organization_id,
57
+ user: obj,
58
+ timestamp: ts,
59
+ auth_hash: auth_hash,
60
+ import: true
61
+ }
62
+
63
+ json = h.to_json
64
+
65
+ endpoint = ENV['RAMEN_IMPORT_URI'] || "https://ramen.is/po.json"
66
+ uri = URI("#{endpoint}?json_payload=#{CGI.escape(json)}")
67
+ resp = Net::HTTP.get_response(uri)
68
+
69
+ if resp.code == "200"
70
+ puts "Imported #{obj[:name]} <#{obj[:email]}>"
71
+ else
72
+ puts "ERROR (#{resp.code}) Importing #{obj[:name]} <#{obj[:email]}>. Continuing...."
73
+ puts resp.body.to_s
74
+ end
75
+ end
76
+ end
77
+ end
@@ -1,3 +1,3 @@
1
1
  module RamenRails
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/ramen-rails.rb CHANGED
@@ -2,6 +2,7 @@ require 'ramen-rails/railtie' if defined?(Rails) && defined?(Rails::Railtie)
2
2
  require 'ramen-rails/config'
3
3
  require 'ramen-rails/script_tag_helper'
4
4
  require 'ramen-rails/ramen_after_filter'
5
+ require 'ramen-rails/import'
5
6
 
6
7
  module RamenRails
7
8
  def self.config
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ramen-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Angilly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-19 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -106,6 +106,7 @@ files:
106
106
  - ".ruby-gemset"
107
107
  - ".ruby-version"
108
108
  - ".travis.yml"
109
+ - CHANGELOG
109
110
  - Gemfile
110
111
  - MIT-LICENSE
111
112
  - README.md
@@ -114,6 +115,7 @@ files:
114
115
  - lib/rails/generators/ramen/config/ramen.rb.erb
115
116
  - lib/ramen-rails.rb
116
117
  - lib/ramen-rails/config.rb
118
+ - lib/ramen-rails/import.rb
117
119
  - lib/ramen-rails/railtie.rb
118
120
  - lib/ramen-rails/ramen_after_filter.rb
119
121
  - lib/ramen-rails/script_tag.rb