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 +4 -4
- data/CHANGELOG +4 -0
- data/README.md +1 -1
- data/lib/ramen-rails/config.rb +3 -1
- data/lib/ramen-rails/import.rb +77 -0
- data/lib/ramen-rails/version.rb +1 -1
- data/lib/ramen-rails.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3491acb100d8b4e8ce91ec01588a4c24baf58d55
|
4
|
+
data.tar.gz: bcc3d1257891f1de2f13d121c627f427f17d91ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11ea9d325e1ab2dc059898b3f52aa4eb9ac048dc3d750e61fdef188021480e5ffffe7471aa928c9cee353d8edaf9909f9fed7682a560fd4335bbc53c4fd915fa
|
7
|
+
data.tar.gz: 63abd2dcf73654e36eecef77ec2de17fb1fa66059620f45dbbf847b4b2a112b1420e54c47647db4bf9bd7b924aade9b0252869ae205f096031d16de6cb8fd915
|
data/CHANGELOG
ADDED
data/README.md
CHANGED
data/lib/ramen-rails/config.rb
CHANGED
@@ -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
|
data/lib/ramen-rails/version.rb
CHANGED
data/lib/ramen-rails.rb
CHANGED
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.
|
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-
|
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
|