apsis-on-steroids 0.0.3 → 0.0.4
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.
- data/VERSION +1 -1
 - data/apsis-on-steroids.gemspec +1 -1
 - data/include/mailing_list.rb +52 -0
 - data/lib/apsis-on-steroids.rb +20 -0
 - data/spec/apsis-on-steroids_spec.rb +7 -0
 - metadata +2 -2
 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.0. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.0.4
         
     | 
    
        data/apsis-on-steroids.gemspec
    CHANGED
    
    
    
        data/include/mailing_list.rb
    CHANGED
    
    | 
         @@ -164,4 +164,56 @@ class ApsisOnSteroids::MailingList < ApsisOnSteroids::SubBase 
     | 
|
| 
       164 
164 
     | 
    
         
             
                  raise "Unexpected result: '#{data}'." if element["Value"] != "Succefully deleted"
         
     | 
| 
       165 
165 
     | 
    
         
             
                end
         
     | 
| 
       166 
166 
     | 
    
         
             
              end
         
     | 
| 
      
 167 
     | 
    
         
            +
              
         
     | 
| 
      
 168 
     | 
    
         
            +
              # Moves a subscriber to the opt-out-list.
         
     | 
| 
      
 169 
     | 
    
         
            +
              def opt_out_subscriber(sub)
         
     | 
| 
      
 170 
     | 
    
         
            +
                res = aos.req_json("v1/optouts/mailinglists/#{data(:id)}/subscribers/queued", :post, :json => [{
         
     | 
| 
      
 171 
     | 
    
         
            +
                  "ExternalId" => "",
         
     | 
| 
      
 172 
     | 
    
         
            +
                  "Reason" => "",
         
     | 
| 
      
 173 
     | 
    
         
            +
                  "SendQueueId" => 0,
         
     | 
| 
      
 174 
     | 
    
         
            +
                  "SubscriberId" => sub.data(:id)
         
     | 
| 
      
 175 
     | 
    
         
            +
                }])
         
     | 
| 
      
 176 
     | 
    
         
            +
                raise "Unexpected result: #{res}" if res["Code"] != 1
         
     | 
| 
      
 177 
     | 
    
         
            +
                data = aos.read_queued_response(res["Result"]["PollURL"])
         
     | 
| 
      
 178 
     | 
    
         
            +
                
         
     | 
| 
      
 179 
     | 
    
         
            +
                raise data if data["FailedSubscriberIds"] && data["FailedSubscriberIds"].any?
         
     | 
| 
      
 180 
     | 
    
         
            +
              end
         
     | 
| 
      
 181 
     | 
    
         
            +
              
         
     | 
| 
      
 182 
     | 
    
         
            +
              # Returns a list of subscribers on the opt-out-list.
         
     | 
| 
      
 183 
     | 
    
         
            +
              def opt_out_list
         
     | 
| 
      
 184 
     | 
    
         
            +
                res = aos.req_json("v1/optouts/mailinglists/#{data(:id)}/queued", :post)
         
     | 
| 
      
 185 
     | 
    
         
            +
                raise "Unexpected result: #{res}" if res["Code"] != 1
         
     | 
| 
      
 186 
     | 
    
         
            +
                data = aos.read_queued_response(res["Result"]["PollURL"])
         
     | 
| 
      
 187 
     | 
    
         
            +
                
         
     | 
| 
      
 188 
     | 
    
         
            +
                ret = []
         
     | 
| 
      
 189 
     | 
    
         
            +
                data.each do |opt_out_data|
         
     | 
| 
      
 190 
     | 
    
         
            +
                  sub = ApsisOnSteroids::Subscriber.new(:aos => aos, :data => {:id => opt_out_data["Id"], :email => opt_out_data["Email"]})
         
     | 
| 
      
 191 
     | 
    
         
            +
                  
         
     | 
| 
      
 192 
     | 
    
         
            +
                  if block_given?
         
     | 
| 
      
 193 
     | 
    
         
            +
                    yield sub
         
     | 
| 
      
 194 
     | 
    
         
            +
                  else
         
     | 
| 
      
 195 
     | 
    
         
            +
                    ret << sub
         
     | 
| 
      
 196 
     | 
    
         
            +
                  end
         
     | 
| 
      
 197 
     | 
    
         
            +
                end
         
     | 
| 
      
 198 
     | 
    
         
            +
                
         
     | 
| 
      
 199 
     | 
    
         
            +
                return ret
         
     | 
| 
      
 200 
     | 
    
         
            +
              end
         
     | 
| 
      
 201 
     | 
    
         
            +
              
         
     | 
| 
      
 202 
     | 
    
         
            +
              # Returns true if the given subscriber is on the opt-out-list.
         
     | 
| 
      
 203 
     | 
    
         
            +
              def opt_out?(sub)
         
     | 
| 
      
 204 
     | 
    
         
            +
                opt_out_list do |sub_opt_out|
         
     | 
| 
      
 205 
     | 
    
         
            +
                  return true if sub_opt_out.data(:email) == sub.data(:email) || sub.data(:id).to_i == sub_opt_out.data(:id).to_i
         
     | 
| 
      
 206 
     | 
    
         
            +
                end
         
     | 
| 
      
 207 
     | 
    
         
            +
                
         
     | 
| 
      
 208 
     | 
    
         
            +
                return false
         
     | 
| 
      
 209 
     | 
    
         
            +
              end
         
     | 
| 
      
 210 
     | 
    
         
            +
              
         
     | 
| 
      
 211 
     | 
    
         
            +
              # Removes the given subscriber from the opt-out-list.
         
     | 
| 
      
 212 
     | 
    
         
            +
              def opt_out_remove_subscriber(sub)
         
     | 
| 
      
 213 
     | 
    
         
            +
                res = aos.req_json("v1/optouts/mailinglists/#{data(:id)}/subscribers/queued", :delete, :json => [
         
     | 
| 
      
 214 
     | 
    
         
            +
                  sub.data(:email)
         
     | 
| 
      
 215 
     | 
    
         
            +
                ])
         
     | 
| 
      
 216 
     | 
    
         
            +
                data = aos.read_queued_response(res["Result"]["PollURL"])
         
     | 
| 
      
 217 
     | 
    
         
            +
                raise data if data["FailedSubscriberEmails"] && data["FailedSubscriberEmails"].any?
         
     | 
| 
      
 218 
     | 
    
         
            +
              end
         
     | 
| 
       167 
219 
     | 
    
         
             
            end
         
     | 
    
        data/lib/apsis-on-steroids.rb
    CHANGED
    
    | 
         @@ -120,6 +120,26 @@ class ApsisOnSteroids 
     | 
|
| 
       120 
120 
     | 
    
         
             
                return res
         
     | 
| 
       121 
121 
     | 
    
         
             
              end
         
     | 
| 
       122 
122 
     | 
    
         | 
| 
      
 123 
     | 
    
         
            +
              def read_queued_response(url)
         
     | 
| 
      
 124 
     | 
    
         
            +
                uri = URI.parse(url)
         
     | 
| 
      
 125 
     | 
    
         
            +
                
         
     | 
| 
      
 126 
     | 
    
         
            +
                Timeout.timeout(300) do
         
     | 
| 
      
 127 
     | 
    
         
            +
                  loop do
         
     | 
| 
      
 128 
     | 
    
         
            +
                    sleep 1
         
     | 
| 
      
 129 
     | 
    
         
            +
                    res = req_json(uri.path)
         
     | 
| 
      
 130 
     | 
    
         
            +
                    
         
     | 
| 
      
 131 
     | 
    
         
            +
                    if res["State"] == "2"
         
     | 
| 
      
 132 
     | 
    
         
            +
                      uri_data = URI.parse(res["DataUrl"])
         
     | 
| 
      
 133 
     | 
    
         
            +
                      return req_json(uri_data.path)
         
     | 
| 
      
 134 
     | 
    
         
            +
                    elsif res["State"] == "1" || res["State"] == "0"
         
     | 
| 
      
 135 
     | 
    
         
            +
                      # Keep waiting.
         
     | 
| 
      
 136 
     | 
    
         
            +
                    else
         
     | 
| 
      
 137 
     | 
    
         
            +
                      raise "Unknown state '#{res["State"]}': #{res}"
         
     | 
| 
      
 138 
     | 
    
         
            +
                    end
         
     | 
| 
      
 139 
     | 
    
         
            +
                  end
         
     | 
| 
      
 140 
     | 
    
         
            +
                end
         
     | 
| 
      
 141 
     | 
    
         
            +
              end
         
     | 
| 
      
 142 
     | 
    
         
            +
              
         
     | 
| 
       123 
143 
     | 
    
         
             
              def parse_obj(obj)
         
     | 
| 
       124 
144 
     | 
    
         
             
                if obj.is_a?(Array)
         
     | 
| 
       125 
145 
     | 
    
         
             
                  ret = []
         
     | 
| 
         @@ -111,5 +111,12 @@ describe "ApsisOnSteroids" do 
     | 
|
| 
       111 
111 
     | 
    
         
             
                  sub.active?.should eql(true)
         
     | 
| 
       112 
112 
     | 
    
         
             
                  mlist.member?(sub).should eql(true)
         
     | 
| 
       113 
113 
     | 
    
         
             
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
                
         
     | 
| 
      
 115 
     | 
    
         
            +
                it "should be able to opt out a subscriber" do
         
     | 
| 
      
 116 
     | 
    
         
            +
                  mlist.opt_out_subscriber(sub)
         
     | 
| 
      
 117 
     | 
    
         
            +
                  mlist.opt_out?(sub).should eql(true)
         
     | 
| 
      
 118 
     | 
    
         
            +
                  mlist.opt_out_remove_subscriber(sub)
         
     | 
| 
      
 119 
     | 
    
         
            +
                  mlist.opt_out?(sub).should eql(false)
         
     | 
| 
      
 120 
     | 
    
         
            +
                end
         
     | 
| 
       114 
121 
     | 
    
         
             
              end
         
     | 
| 
       115 
122 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            name: apsis-on-steroids
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
4 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       5 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 5 
     | 
    
         
            +
              version: 0.0.4
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
       8 
8 
     | 
    
         
             
            - kaspernj
         
     | 
| 
         @@ -144,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       144 
144 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       145 
145 
     | 
    
         
             
                  segments:
         
     | 
| 
       146 
146 
     | 
    
         
             
                  - 0
         
     | 
| 
       147 
     | 
    
         
            -
                  hash: - 
     | 
| 
      
 147 
     | 
    
         
            +
                  hash: -3749909533048990827
         
     | 
| 
       148 
148 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       149 
149 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       150 
150 
     | 
    
         
             
              none: false
         
     |