Class: ZuoraClient
- Inherits:
-
Object
- Object
- ZuoraClient
- Defined in:
- lib/zuora_client.rb
Constant Summary collapse
- PROD_URL =
'https://www.zuora.com/apps/services/a/27.0'
- SANDBOX_URL =
'https://apisandbox.zuora.com/apps/services/a/27.0'
Class Method Summary collapse
Instance Method Summary collapse
- #create(obj) ⇒ Object
- #delete(type, ids) ⇒ Object
- #generate(obj) ⇒ Object
-
#initialize(username, password, url = PROD_URL) ⇒ ZuoraClient
constructor
A new instance of ZuoraClient.
- #query(query_string) ⇒ Object
- #subscribe(obj) ⇒ Object
- #update(obj) ⇒ Object
Constructor Details
#initialize(username, password, url = PROD_URL) ⇒ ZuoraClient
Returns a new instance of ZuoraClient.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/zuora_client.rb', line 65 def initialize(username, password, url=PROD_URL) $ZUORA_USER = username $ZUORA_PASSWORD = password $ZUORA_ENDPOINT = url @client = ZuoraInterface.new # add custom fields, if any custom_fields = ZuoraClient.parse_custom_fields @client.session_start(custom_fields) end |
Class Method Details
.parse_custom_fields ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/zuora_client.rb', line 50 def self.parse_custom_fields custom_fields = YAML.load_file(File.dirname(__FILE__) + '/../custom_fields.yml') if custom_fields custom_fields.each do |key, value| fields = value.strip.split(/\s+/).map { |e| "#{e}__c" } type_class = Object.const_get('ZUORA').const_get(key) fields.each do |field| custom_field = field.gsub(/^\w/) { |i| i.downcase } type_class.send :attr_accessor, custom_field end end end custom_fields end |
Instance Method Details
#create(obj) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/zuora_client.rb', line 112 def create(obj) begin response = @client.create(obj) result = save_results_to_hash(response) rescue Exception => e puts e. end result || [] end |
#delete(type, ids) ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/zuora_client.rb', line 142 def delete(type, ids) begin response = @client.delete(type, ids) result = save_results_to_hash(response) rescue Exception => e puts e. end result || [] end |
#generate(obj) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/zuora_client.rb', line 122 def generate(obj) begin response = @client.generate(obj) result = save_results_to_hash(response) rescue Exception => e puts e. end result || [] end |
#query(query_string) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/zuora_client.rb', line 77 def query(query_string) query_string =~ /select\s+(.+)\s+from/i fields = ($1.split /,\s+/).map do |f| f.gsub!(/\b\w/) { $&.downcase } end begin response = @client.query(query_string) rescue Exception => e puts e. end result = [] if response && response.result && response.result.size > 0 response.result.records.each do |record| row = {} fields.each do |f| row[f] = record.send(f) end result << row end end result end |
#subscribe(obj) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/zuora_client.rb', line 103 def subscribe(obj) begin response = @client.subscribe(obj) return response rescue Exception => e puts e. end end |
#update(obj) ⇒ Object
132 133 134 135 136 137 138 139 140 |
# File 'lib/zuora_client.rb', line 132 def update(obj) begin response = @client.update(obj) result = save_results_to_hash(response) rescue Exception => e puts e. end result || [] end |