Tabnine Logo
NewsletterPublisher
Code IndexAdd Tabnine to your IDE (free)

How to use
NewsletterPublisher
in
com.novoda.enews

Best Java code snippets using com.novoda.enews.NewsletterPublisher (Showing top 4 results out of 315)

origin: novoda/spikes

  public NewsletterPublisher newInstance(String mailChimpToken) {
    OkHttpClient okHttpClient = new OkHttpClient.Builder()
        .addInterceptor(new AuthHeaderInterceptor(mailChimpToken))
        .build();
    Retrofit retrofit = new Retrofit.Builder()
        .client(okHttpClient)
        .baseUrl("https://us5.api.mailchimp.com/3.0/")
        .addConverterFactory(new ConverterFactory())
        .build();
    MailChimpWebService webService = retrofit.create(MailChimpWebService.class);
    NewsletterScheduler newsletterScheduler = new NewsletterScheduler(webService);
    return new NewsletterPublisher(webService, "187645ff44", newsletterScheduler);
  }
}
origin: novoda/spikes

public void publish(String html, LocalDateTime atLocalDateTime) {
  Response<ApiCampaignResult> campaignResultResponse = postCampaign();
  if (campaignResultResponse.isSuccessful()) {
    String id = campaignResultResponse.body().id;
    putCampaignContent(id, html);
    scheduleNewsletter(id, atLocalDateTime);
  } else {
    ResponseBody responseBody = campaignResultResponse.errorBody();
    try {
      System.err.println(responseBody.string());
    } catch (IOException e) {
      throw new IllegalStateException("We failed to debug.", e);
    }
    throw new IllegalStateException("We failed " + campaignResultResponse.code());
  }
}
origin: novoda/spikes

  @Override
  public Response handleRequest(Request input, Context context) {
    String slackToken = input.getSlackToken();
    String mailChimpApiKey = input.getMailChimpApiKey();

    Scraper scraper = new Scraper.Factory().newInstance(slackToken);
    HtmlGenerator htmlGenerator = new HtmlGenerator.Factory().newInstance();
    NewsletterPublisher newsletterPublisher = new NewsletterPublisher.Factory().newInstance(mailChimpApiKey);
    ArticleEditor articleEditor = new ArticleEditor.Factory().newInstance();

    LocalDateTime start = LocalDateTime.now();
    LocalDateTime end = LocalDateTime.now().minusDays(6);
    Stream<ChannelHistory.Message> messageStream = scraper.scrape(start, end);
    Stream<Article> articleStream = articleEditor.generateArticle(messageStream);
    String html = htmlGenerator.generate(articleStream);
    LocalDateTime atLocalDateTime = LocalDateTime.now().plusDays(1).plusHours(1);
    newsletterPublisher.publish(html, atLocalDateTime);
    // Time warp campaigns have to be 24 hours in the future
    // The scheduling is completely hidden here and is a TODO
    // - because if someone set up a cron job they cannot *fully* control the time right now

    JsonObject jsonObject = new JsonObject();
    jsonObject.add("message", new JsonPrimitive("complete!"));
    return new Response(jsonObject.getAsJsonObject().toString());
  }
}
origin: novoda/spikes

  /**
   * @param args https://api.slack.com/docs/oauth-test-tokens, https://us5.admin.mailchimp.com/account/api/
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {
    if (args.length == 0 || args.length < 2) {
      throw new IllegalStateException("You need to pass a Slack token as the first arg and MailChimp API token as the second.");
    }
    String slackToken = args[0];
    String mailChimpToken = args[1];
    Scraper scraper = new Scraper.Factory().newInstance(slackToken);
    HtmlGenerator htmlGenerator = new HtmlGenerator.Factory().newInstance();
    ArticleEditor articleEditor = new ArticleEditor.Factory().newInstance();
    NewsletterPublisher newsletterPublisher = new NewsletterPublisher.Factory().newInstance(mailChimpToken);

    LocalDateTime start = LocalDateTime.now();
    LocalDateTime end = LocalDateTime.now().minusDays(6);
    Stream<ChannelHistory.Message> messageStream = scraper.scrape(start, end);
    Stream<Article> articleStream = articleEditor.generateArticle(messageStream);
    String html = htmlGenerator.generate(articleStream);
    LocalDateTime atLocalDateTime = LocalDateTime.now().plusDays(1).plusHours(1);
    newsletterPublisher.publish(html, atLocalDateTime);
    // Time warp campaigns have to be 24 hours in the future
    // The scheduling is completely hidden here and is a TODO
    // - because if someone set up a cron job they cannot *fully* control the time right now
  }
}
com.novoda.enewsNewsletterPublisher

Most used methods

  • publish
  • <init>
  • postCampaign
  • putCampaignContent
  • scheduleNewsletter

Popular in Java

  • Making http requests using okhttp
  • getContentResolver (Context)
  • setScale (BigDecimal)
  • notifyDataSetChanged (ArrayAdapter)
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now