ramen-rails 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +3 -0
- data/lib/ramen-rails/config.rb +26 -3
- data/lib/ramen-rails/import.rb +42 -15
- data/lib/ramen-rails/version.rb +1 -1
- data/spec/lib/import_spec.rb +44 -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: 9de77426d862cf8695c418cc468c76e3760a89cd
|
4
|
+
data.tar.gz: b09b033f511c2a342e1eac842a14068d2fb4fd98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acb1e662f59381d32a1bc9fb764c94b2de8e6bf138aaf63d150c0afcba4e6f271d8dd2211d894d1430ddca5a5e262f951713ea80227f4e0868a7cd91f9938cad
|
7
|
+
data.tar.gz: 6937e82d0cf6a6bd1cd1a8472ec4f446d7e25a55a3d0a865b2914b54c5e7a563f1c33dc4059f14a9ad2c53607cb20670f02c895fd8e784793e94d8b82b160ae0
|
data/CHANGELOG
CHANGED
data/lib/ramen-rails/config.rb
CHANGED
@@ -10,9 +10,7 @@ module RamenRails
|
|
10
10
|
:return_url,
|
11
11
|
:return_label,
|
12
12
|
:ramen_js_asset_uri,
|
13
|
-
:custom_links
|
14
|
-
:import_user_labels,
|
15
|
-
:import_user_value
|
13
|
+
:custom_links
|
16
14
|
|
17
15
|
def ensure_not_lambda!(v)
|
18
16
|
if v.lambda?
|
@@ -85,6 +83,31 @@ module RamenRails
|
|
85
83
|
def current_user_labels
|
86
84
|
@current_user_labels
|
87
85
|
end
|
86
|
+
|
87
|
+
attr_reader :import_company_labels
|
88
|
+
def import_company_labels=(value)
|
89
|
+
raise ArgumentError, "import_company_labels should be a Proc" unless value.kind_of?(Proc)
|
90
|
+
ensure_not_lambda!(value)
|
91
|
+
|
92
|
+
@import_company_labels = value
|
93
|
+
end
|
94
|
+
|
95
|
+
attr_reader :import_user_labels
|
96
|
+
def import_user_labels=(value)
|
97
|
+
raise ArgumentError, "import_user_labels should be a Proc" unless value.kind_of?(Proc)
|
98
|
+
ensure_not_lambda!(value)
|
99
|
+
|
100
|
+
@import_user_labels = value
|
101
|
+
end
|
102
|
+
|
103
|
+
attr_reader :import_user_value
|
104
|
+
def import_user_value=(value)
|
105
|
+
raise ArgumentError, "import_user_value should be a Proc" unless value.kind_of?(Proc)
|
106
|
+
ensure_not_lambda!(value)
|
107
|
+
|
108
|
+
@import_user_value = value
|
109
|
+
end
|
110
|
+
|
88
111
|
|
89
112
|
def organization_id=(value)
|
90
113
|
@organization_id = value
|
data/lib/ramen-rails/import.rb
CHANGED
@@ -12,9 +12,15 @@ module RamenRails
|
|
12
12
|
end
|
13
13
|
|
14
14
|
attr_accessor :user
|
15
|
+
attr_accessor :company
|
15
16
|
|
16
|
-
def initialize(opts)
|
17
|
+
def initialize(opts = {})
|
17
18
|
self.user = opts[:user]
|
19
|
+
self.company = opts[:company]
|
20
|
+
end
|
21
|
+
|
22
|
+
def can_get_company_labels?
|
23
|
+
RamenRails.config.import_company_labels.present?
|
18
24
|
end
|
19
25
|
|
20
26
|
def can_get_labels?
|
@@ -25,6 +31,11 @@ module RamenRails
|
|
25
31
|
RamenRails.config.import_user_value.present?
|
26
32
|
end
|
27
33
|
|
34
|
+
def get_company_labels
|
35
|
+
company.
|
36
|
+
instance_eval(&RamenRails.config.import_company_labels)
|
37
|
+
end
|
38
|
+
|
28
39
|
def get_labels
|
29
40
|
user.
|
30
41
|
instance_eval(&RamenRails.config.import_user_labels)
|
@@ -36,10 +47,37 @@ module RamenRails
|
|
36
47
|
end
|
37
48
|
|
38
49
|
def import
|
50
|
+
h = generate_hash
|
51
|
+
json = h.to_json
|
52
|
+
|
53
|
+
endpoint = ENV['RAMEN_IMPORT_URI'] || "https://ramen.is/po.json"
|
54
|
+
uri = URI("#{endpoint}?json_payload=#{CGI.escape(json)}")
|
55
|
+
start = Time.now.to_f
|
56
|
+
resp = Net::HTTP.get_response(uri)
|
57
|
+
total = Time.now.to_f - start
|
58
|
+
|
59
|
+
if resp.code == "200"
|
60
|
+
puts "Imported #{obj[:name]} <#{obj[:email]}> in #{total} seconds"
|
61
|
+
else
|
62
|
+
puts "ERROR (#{resp.code}) Importing #{obj[:name]} <#{obj[:email]}>. Continuing...."
|
63
|
+
puts resp.body.to_s
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def generate_hash
|
39
68
|
obj = {}
|
40
69
|
[:email, :name, :id].each do |attr|
|
41
70
|
obj[attr] = user.send(attr)
|
42
71
|
end
|
72
|
+
|
73
|
+
company_obj = {}
|
74
|
+
if company
|
75
|
+
[:url, :name, :id].each do |attr|
|
76
|
+
company_obj[attr] = user.send(attr)
|
77
|
+
end
|
78
|
+
|
79
|
+
company_obj[:labels] = get_company_labels if can_get_company_labels?
|
80
|
+
end
|
43
81
|
|
44
82
|
obj[:labels] = get_labels if can_get_labels?
|
45
83
|
obj[:value] = get_value if can_get_value?
|
@@ -60,20 +98,9 @@ module RamenRails
|
|
60
98
|
import: true
|
61
99
|
}
|
62
100
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
uri = URI("#{endpoint}?json_payload=#{CGI.escape(json)}")
|
67
|
-
start = Time.now.to_f
|
68
|
-
resp = Net::HTTP.get_response(uri)
|
69
|
-
total = Time.now.to_f - start
|
70
|
-
|
71
|
-
if resp.code == "200"
|
72
|
-
puts "Imported #{obj[:name]} <#{obj[:email]}> in #{total} seconds"
|
73
|
-
else
|
74
|
-
puts "ERROR (#{resp.code}) Importing #{obj[:name]} <#{obj[:email]}>. Continuing...."
|
75
|
-
puts resp.body.to_s
|
76
|
-
end
|
101
|
+
h[:company] = company_obj if company_obj.present?
|
102
|
+
|
103
|
+
h
|
77
104
|
end
|
78
105
|
end
|
79
106
|
end
|
data/lib/ramen-rails/version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "RamenRails::Import" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@user = Hashie::Mash.new(name: 'Ryan', email: 'ryan@ramen.is', id: '1234')
|
7
|
+
@organization_id = rand(1_000_000)
|
8
|
+
@organization_secret = rand(1_000_000)
|
9
|
+
|
10
|
+
RamenRails.config do |config|
|
11
|
+
config.organization_id = @organization_id
|
12
|
+
config.organization_secret = @organization_secret
|
13
|
+
config.current_user = Proc.new { @user }
|
14
|
+
end
|
15
|
+
|
16
|
+
@importer = RamenRails::Import.new
|
17
|
+
@importer.user = @user
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have user info in hash" do
|
21
|
+
expect(@importer.generate_hash[:user][:email]).
|
22
|
+
to eq('ryan@ramen.is')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not have company data" do
|
26
|
+
expect(@importer.generate_hash[:company]).to be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should set :import true" do
|
30
|
+
expect(@importer.generate_hash[:import]).to eq(true)
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with a company" do
|
34
|
+
before :each do
|
35
|
+
@company = Hashie::Mash.new({id: 1234, url: 'https://ramen.is', name: 'Fake Rake'})
|
36
|
+
@importer.company = @company
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should have company data" do
|
40
|
+
expect(@importer.generate_hash[:company][:id]).
|
41
|
+
to eq("1234")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
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.5.
|
4
|
+
version: 0.5.1
|
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-06-
|
11
|
+
date: 2015-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- lib/ramen-rails/version.rb
|
124
124
|
- ramen-rails.gemspec
|
125
125
|
- spec/lib/config_spec.rb
|
126
|
+
- spec/lib/import_spec.rb
|
126
127
|
- spec/lib/ramen_after_filter_spec.rb
|
127
128
|
- spec/lib/script_tag_helper_spec.rb
|
128
129
|
- spec/spec_helper.rb
|
@@ -152,6 +153,7 @@ specification_version: 4
|
|
152
153
|
summary: Rails gem for Ramen (https://ramen.is)
|
153
154
|
test_files:
|
154
155
|
- spec/lib/config_spec.rb
|
156
|
+
- spec/lib/import_spec.rb
|
155
157
|
- spec/lib/ramen_after_filter_spec.rb
|
156
158
|
- spec/lib/script_tag_helper_spec.rb
|
157
159
|
- spec/spec_helper.rb
|