tend-ruby 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8371ebedf83498b8009b0eab198d55cea5ead22
4
- data.tar.gz: f35a63e52f9743f67b017ccb4c7988c1f5394107
3
+ metadata.gz: 88a5e76958cde80ceeffda6d9ab5f7e460d9ab5e
4
+ data.tar.gz: 2532e1f93d9f730a76a8ac5a4a483bbd71b99229
5
5
  SHA512:
6
- metadata.gz: 27662f774c18274913cbcca6699f7d8e595cf299967109e7f8bf06ba2e34c3afff2bb7a2e170178b4b75a38a84a4939e12eff2de51a8c361855deb60eb7d17fb
7
- data.tar.gz: 0107a58b4d1c6e8d702b7fd8d90875bab9c842650b92d599c1d6c25e4a8add7da704ccb14dc23a4657f732fcbb7064422166572573d664fc06ef3cb446b99705
6
+ metadata.gz: 2e08fa1f69d68e9e64709157f99afb726ebfdf7603c995a5e8aa85c142dc847ecfd2076910e385e8d5617f47a40999d3a7ee1b882ef2f25ba6a9f6f9a96b734e
7
+ data.tar.gz: 4bc3e7ea49317caae6fe3c0a082df16050e9851d5e06055d4f9df51447fb58e88dce2de0c638594eb3c3ce21eb68ef6fea484833ac7d818a74868ee7fb933fd3
data/README.md CHANGED
@@ -6,7 +6,7 @@ Ruby wrapper of Tend.io API
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'tend-ruby'
9
+ gem 'tend-ruby', require: "tend"
10
10
 
11
11
  And then execute:
12
12
 
@@ -27,7 +27,7 @@ Tend.password = "sdnf9283*hwer"
27
27
 
28
28
  * View all contacts
29
29
 
30
- $Tend::Contact.all
30
+ Tend::Contact.all
31
31
 
32
32
 
33
33
  ## Contributing
@@ -15,6 +15,7 @@ require "tend/util/no_delete"
15
15
  require "tend/util/no_find"
16
16
  require "tend/errors/http_error"
17
17
  require "tend/errors/not_supported_error"
18
+ require "tend/models/collection"
18
19
  require "tend/models/garden"
19
20
  require "tend/models/campaign"
20
21
  require "tend/models/contact"
@@ -0,0 +1,13 @@
1
+ class Tend::Collection < Array
2
+
3
+ attr_accessor :total_count, :total_pages, :current_page, :limit
4
+
5
+ def init paginator = {}
6
+ return unless paginator
7
+ paginator.each do |k,v|
8
+ next unless respond_to? "#{k}="
9
+ send "#{k}=", v
10
+ end
11
+ end
12
+
13
+ end
@@ -14,16 +14,15 @@ class Tend::Garden
14
14
  class << self
15
15
  def all options = {}
16
16
  response = get options
17
- #return response
18
- response.map { |object| new(object) }
17
+ fill_collection response, self
19
18
  end
20
19
 
21
20
  def find id, options = {}
22
- new( get( options.merge(id: id, no_pagination: true) ) )
21
+ new( get( options.merge(id: id, no_pagination: true) )[:data] )
23
22
  end
24
23
 
25
24
  def create attributes, options = {}
26
- new( post attributes, options )
25
+ new( post( attributes, options)[:data] )
27
26
  end
28
27
 
29
28
  end
@@ -40,11 +39,7 @@ class Tend::Garden
40
39
 
41
40
  def collection name, cla, options = {}
42
41
  response = get options.merge(collection: name, id: id)
43
- a = []
44
- response.each do |h|
45
- a << cla.new(h)
46
- end
47
- a
42
+ self.class.fill_collection response, cla
48
43
  end
49
44
 
50
45
  end
@@ -16,7 +16,7 @@ class Tend::Segment < Tend::Garden
16
16
 
17
17
  def self.call_remote_method remote_method, email, segments = [], options = {}
18
18
  segs = segments.split(",").join(",")
19
- post( {email: email, segments: segs}, options.merge(collection: remote_method, no_pagination: true))
19
+ post( {email: email, segments: segs}, options.merge(collection: remote_method, no_pagination: true))[:message]
20
20
  end
21
21
 
22
22
 
@@ -20,8 +20,10 @@ module Tend::Util::Ht
20
20
  def handle_response response
21
21
  case response.code
22
22
  when 200..299
23
- #p response
24
- response.parsed_response["data"] || response.parsed_response["message"]
23
+ data = response.parsed_response["data"]
24
+ message = response.parsed_response["message"]
25
+ paginator = response.parsed_response["paginator"]
26
+ {data: data, message: message, paginator: paginator}
25
27
  when 422
26
28
  HashWithIndifferentAccess.new response.parsed_response
27
29
  else
@@ -35,13 +37,13 @@ module Tend::Util::Ht
35
37
 
36
38
  def delete options = {}
37
39
  o = extract_options options.merge(id: id, no_pagination: true)
38
- initialize self.class.send( :handle_response, HTTParty.delete( uri(o), :basic_auth => o.auth ) )
40
+ initialize self.class.send( :handle_response, HTTParty.delete( uri(o), :basic_auth => o.auth ) )[:data]
39
41
  self
40
42
  end
41
43
 
42
44
  def update attributes, options = {}
43
45
  o = extract_options options.merge(id: id, no_pagination: true)
44
- initialize self.class.send( :handle_response, HTTParty.put( uri(o), body: attributes, :basic_auth => o.auth ) )
46
+ initialize self.class.send( :handle_response, HTTParty.put( uri(o), body: attributes, :basic_auth => o.auth ) )[:data]
45
47
  self
46
48
  end
47
49
 
@@ -3,6 +3,13 @@
3
3
  module Tend::Util::Util
4
4
  module ClassMethods
5
5
 
6
+ def fill_collection response, cla
7
+ collection = Tend::Collection.new
8
+ collection.init response[:paginator]
9
+ response[:data].each { |object| collection << cla.new(object) }
10
+ collection
11
+ end
12
+
6
13
  private
7
14
  def extract_options options = {}
8
15
  o = OpenStruct.new({
@@ -1,3 +1,3 @@
1
1
  module Tend
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tend-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - stevenbristol
@@ -125,6 +125,7 @@ files:
125
125
  - lib/tend/errors/http_error.rb
126
126
  - lib/tend/errors/not_supported_error.rb
127
127
  - lib/tend/models/campaign.rb
128
+ - lib/tend/models/collection.rb
128
129
  - lib/tend/models/contact.rb
129
130
  - lib/tend/models/garden.rb
130
131
  - lib/tend/models/page.rb