Skip to content
This repository was archived by the owner on Dec 9, 2020. It is now read-only.

Commit ddf453c

Browse files
committed
Moving instance var loading into yml file
1 parent 2f044e5 commit ddf453c

File tree

4 files changed

+117
-5
lines changed

4 files changed

+117
-5
lines changed

config/model_properties.yml

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
Natero::Base:
3+
source: ~
4+
properties:
5+
6+
Natero::Account:
7+
source: http://apidocs.natero.com/apidoc.html#Accounts
8+
properties:
9+
- account_id
10+
- name
11+
- join_date
12+
- renewal_date
13+
- billing_account_id
14+
- support_account_id
15+
- crm_account_id
16+
- billing_street
17+
- billing_city
18+
- billing_postal_code
19+
- billing_state
20+
- billing_country
21+
- phone
22+
- employees
23+
- industry
24+
- tier
25+
- csm_score
26+
- current_nps_score
27+
- sales_rep_name
28+
- sales_rep_email
29+
- source
30+
- stage
31+
- is_deleted
32+
- is_churned
33+
- inactive_time
34+
- inactive_reason
35+
- parent_account_id
36+
- hierarchy_label
37+
- is_leaf
38+
- latest_status_title
39+
- latest_status_details
40+
- latest_status_date
41+
- assigned_csms
42+
- custom_label_dimensions
43+
- custom_value_dimensions
44+
- custom_event_dimensions
45+
- stage_history
46+
- nps_history
47+
48+
Natero::Event:
49+
source: http://apidocs.natero.com/restapi.html
50+
properties:
51+
- account_id
52+
- action
53+
- active_duration
54+
- created_at
55+
- details
56+
- feature
57+
- module
58+
- product
59+
- session_id
60+
- time_spent
61+
- total
62+
- user_id
63+
64+
Natero::Metric:
65+
source: http://apidocs.natero.com/apidoc.html#Custom%20Metrics
66+
properties:
67+
- account_id
68+
- name
69+
- metrics
70+
- direction
71+
- page
72+
73+
Natero::User:
74+
source: http://apidocs.natero.com/apidoc.html#Accounts%20Product%20Users
75+
properties:
76+
- user_id
77+
- account_id
78+
- first_name
79+
- last_name
80+
- contact_user_id
81+
- phone
82+
- mobile_phone
83+
- email
84+
- salutation
85+
- title
86+
- role
87+
- department
88+
- source
89+
- mailing_street
90+
- mailing_city
91+
- mailing_state
92+
- mailing_postal_code
93+
- mailing_country
94+
- lead_source
95+
- product_join_date
96+
- is_active
97+
- custom_label_dimensions
98+
- custom_value_dimensions
99+
- custom_event_dimensions
100+
...

lib/natero.rb

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def self.api_key_uri
4040
def self.to_records_json(objects)
4141
"{\"records\": #{Array(objects).map(&:serialize)}}".to_s.delete('\\').gsub('"{', '{').gsub('}"', '}')
4242
end
43+
44+
def self.gem_root
45+
File.expand_path('../..', __FILE__)
46+
end
4347
end
4448

4549
require_relative 'natero/serializable'

lib/natero/base.rb

+12-4
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,22 @@ def initialize(params, raw_response = nil)
3939
missing_params = REQUIRED_PARAMS - params.keys
4040
raise ArgumentError.new("Missing required params #{missing_params.join(', ')}") unless missing_params.empty?
4141

42-
params.each do |k, v|
43-
instance_variable_set("@#{k}", v)
44-
self.class.class_eval { attr_reader :"#{k}" }
45-
end
42+
load_properties(params)
4643
@raw_response = raw_response
4744
end
4845

4946
def to_json
5047
serialize
5148
end
49+
50+
def load_properties(params)
51+
model_config_file = "#{Natero.gem_root}/config/model_properties.yml"
52+
model_config = YAML::load(File.read(model_config_file))[self.class.name.to_s].with_indifferent_access
53+
model_config[:properties].each do |prop|
54+
next unless params.include?(prop.to_sym)
55+
56+
instance_variable_set("@#{prop}", params[prop.to_sym])
57+
self.class.class_eval { attr_reader prop.to_sym }
58+
end
59+
end
5260
end

spec/natero/event_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
details = 'detail!'
5050
request_url = "https://events.natero.com/v1/#{event_auth_key}/#{event_api_key}"
5151
data = {body: {id:1, name:'test', action:'identifyAccount', details: details},
52-
header: {'Content-Type': 'application/json'}}
52+
headers: {'Content-Type': 'application/json'}}
5353
method = :post
5454

5555
expect(HTTParty).to receive(method).with(request_url, data).and_return(valid_message)

0 commit comments

Comments
 (0)