// GetFeed takes an API key generated from http://datamine.mta.info/user/register
// and a boolean specifying which feed (1,2,3,4,5,6,S trains OR L train) and
// it will return a transit_realtime.FeedMessage with NYCT extensions.
966775
func GetFeed(ctx context.Context, key string, ft FeedType) (*FeedMessage, error) {
	url := "http://datamine.mta.info/mta_esi.php?key=" + key +
		"&feed_id=" + strconv.Itoa(int(ft))
	resp, err := http.Get(url)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

	transit := &transit_realtime.FeedMessage{}
	err = proto.Unmarshal(body, transit)
	if err != nil {
		return nil, err
	}
	return &FeedMessage{*transit}, nil
}
455029
func Changefeed(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	var (
		vars                = mux.Vars(r)
		logger              = ctxu.GetLogger(ctx)
		qs                  = r.URL.Query()
		gun                 = vars["gun"]
		changeID            = qs.Get("change_id")
		store, records, err = checkChangefeedInputs(logger, ctx.Value(notary.CtxKeyMetaStore), qs.Get("records"))
	)
	if err != nil {
		// err already logged and in correct format.
		return err
	}
	out, err := changefeed(logger, store, gun, changeID, records)
	if err == nil {
		w.Write(out)
	}
	return err
}
940289
func retrieveFeeds(c *context.Context, ctxUser *models.User, userID int64, isProfile bool) {
	actions, err := models.GetFeeds(ctxUser, userID, c.QueryInt64("after_id"), isProfile)
	if err != nil {
		c.Handle(500, "GetFeeds", err)
		return
	}

	// Check access of private repositories.
	feeds := make([]*models.Action, 0, len(actions))
	unameAvatars := make(map[string]string)
	for _, act := range actions {
		// Cache results to reduce queries.
		_, ok := unameAvatars[act.ActUserName]
		if !ok {
			u, err := models.GetUserByName(act.ActUserName)
			if err != nil {
				if errors.IsUserNotExist(err) {
					continue
				}
				c.Handle(500, "GetUserByName", err)
				return
			}
			unameAvatars[act.ActUserName] = u.RelAvatarLink()
		}

		act.ActAvatar = unameAvatars[act.ActUserName]
		feeds = append(feeds, act)
	}
	c.Data["Feeds"] = feeds
	if len(feeds) > 0 {
		afterID := feeds[len(feeds)-1].ID
		c.Data["AfterID"] = afterID
		c.Header().Set("X-AJAX-URL", fmt.Sprintf("%s?after_id=%d", c.Data["Link"], afterID))
	}
}
235043
func (c *Client) GetFeedPath(stream, direction string, version int, pageSize int) (string, error) {
	ps := pageSize

	dir := ""
	switch direction {
	case "forward", "backward":
		dir = direction
	default:
		return "", fmt.Errorf("Invalid Direction %s. Allowed values are \"forward\" or \"backward\" \n", direction)
	}

	v := "head"
	if version >= 0 {
		v = strconv.Itoa(version)
	}

	if v == "head" && dir == "forward" {
		return "", fmt.Errorf("Invalid Direction (%s) and version (head) combination.\n", direction)
	}

	return fmt.Sprintf("/streams/%s/%s/%s/%d", stream, v, dir, ps), nil
}
1135803
func (class *tCharClass) GetRuneAt(i int32) rune {
	for _, r := range class.Ranges {
		if i < r.Size {
			return r.Start + rune(i)
		}
		i -= r.Size
	}
	panic("index out of bounds")
}
1329971
func (m *MockTag) ForFeed(arg0 content.Feed, arg1 content.User) ([]content.Tag, error) {
	ret := m.ctrl.Call(m, "ForFeed", arg0, arg1)
	ret0, _ := ret[0].([]content.Tag)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
783079
func (c *Client) Get(ctx context.Context, id string) (m Model, err error) {
	uri := fmt.Sprintf("%s/datasets/%s", c.url, id)

	clientlog.Do(ctx, "retrieving dataset", service, uri)

	req, err := http.NewRequest("GET", uri, nil)
	if err != nil {
		return
	}

	resp, err := c.cli.Do(ctx, req)
	if err != nil {
		return
	}

	if resp.StatusCode != http.StatusOK {
		err = NewDatasetAPIResponse(resp, uri)
		return
	}

	b, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return
	}
	defer resp.Body.Close()

	var body map[string]interface{}
	if err = json.Unmarshal(b, &body); err != nil {
		return
	}

	// TODO: Authentication will sort this problem out for us. Currently
	// the shape of the response body is different if you are authenticated
	// so return the "next" item only
	if next, ok := body["next"]; ok && (common.IsCallerPresent(ctx) || common.IsFlorenceIdentityPresent(ctx)) {
		b, err = json.Marshal(next)
		if err != nil {
			return
		}
	}

	err = json.Unmarshal(b, &m)
	return
}
926423
func (w *WebAPIFeeEstimator) getCachedFee(numBlocks uint32) (uint32, error) {
	w.feesMtx.Lock()
	defer w.feesMtx.Unlock()

	// Search our cached fees for the desired block target. If the target is
	// not cached, then attempt to extrapolate it from the next lowest target
	// that *is* cached. If we successfully extrapolate, then cache the
	// target's fee.
	for target := numBlocks; target >= minBlockTarget; target-- {
		fee, ok := w.feeByBlockTarget[target]
		if !ok {
			continue
		}

		_, ok = w.feeByBlockTarget[numBlocks]
		if !ok {
			w.feeByBlockTarget[numBlocks] = fee
		}
		return fee, nil
	}
	return 0, fmt.Errorf("web API does not include a fee estimation for "+
		"block target of %v", numBlocks)
}
237052
func FetchFeedFiles(reqs []FetchRequest) (results []FetchResult, err error) {
	reqChan := make(chan FetchRequest, len(reqs))
	resChan := make(chan FetchResult, len(reqs))
	errChan := make(chan error, len(reqs))
	defer close(reqChan)
	defer close(resChan)
	defer close(errChan)

	for _, r := range reqs {
		log.Infof("Fetching... %s", r.URL)
	}

	go func() {
		for _, r := range reqs {
			reqChan <- r
		}
	}()

	concurrency := len(reqs)
	tasks := util.GenWorkers(concurrency)
	for range reqs {
		tasks <- func() {
			select {
			case req := <-reqChan:
				body, err := fetchFile(req, 20/len(reqs))
				if err != nil {
					errChan <- err
					return
				}
				resChan <- FetchResult{
					Year: req.Year,
					URL:  req.URL,
					Body: body,
				}
			}
			return
		}
	}

	errs := []error{}
	timeout := time.After(10 * 60 * time.Second)
	for range reqs {
		select {
		case res := <-resChan:
			results = append(results, res)
			log.Infof("Fetched... %s", res.URL)
		case err := <-errChan:
			errs = append(errs, err)
		case <-timeout:
			return results, fmt.Errorf("Timeout Fetching")
		}
	}
	if 0 < len(errs) {
		return results, fmt.Errorf("%s", errs)
	}
	return results, nil
}
543298
func (p *PushEventRepository) GetFork() bool {
	if p == nil || p.Fork == nil {
		return false
	}
	return *p.Fork
}
997360
func (bot TgBot) GetMe() (User, error) {
	body, err := getPetition(bot.buildPath("getMe"), nil)

	if err != nil {
		return User{}, err
	}

	var data ResultGetUser
	dec := json.NewDecoder(strings.NewReader(body))
	dec.Decode(&data)

	if !data.Ok {
		errc := 403
		desc := ""
		if data.ErrorCode != nil {
			errc = *data.ErrorCode
		}
		if data.Description != nil {
			desc = *data.Description
		}

		errormsg := fmt.Sprintf("Some error happened, maybe your token is bad:\nError code: %d\nDescription: %s\nToken: %s", errc, desc, bot.Token)
		return User{}, errors.New(errormsg)
	}
	return data.Result, nil
}
1185458
func Fetch(metas []models.FeedMeta) ([]Item, error) {
	reqs := []fetcher.FetchRequest{}
	for _, meta := range metas {
		reqs = append(reqs, fetcher.FetchRequest{
			URL: meta.URL,
		})
	}

	results, err := fetcher.FetchFeedFiles(reqs)
	if err != nil {
		return nil,
			fmt.Errorf("Failed to fetch. err: %s", err)
	}

	items := []Item{}
	for _, res := range results {
		var rdf rdf
		if err = xml.Unmarshal([]byte(res.Body), &rdf); err != nil {
			return nil, fmt.Errorf(
				"Failed to unmarshal. url: %s, err: %s", res.URL, err)
		}
		items = append(items, rdf.Items...)
	}
	return items, nil

}
750895
func (t *Tag) GetMessage() string {
	if t == nil || t.Message == nil {
		return ""
	}
	return *t.Message
}
844567
func (self *Future) Get() (interface{}, error) {
	self.mutex.Lock()
	defer self.mutex.Unlock()
	for {
		if self.received {
			return self.val, self.err
		}
		self.cond.Wait()
	}
}
368624
func (c *Client) QueryFeed(query *feed.Query, manifestAddressOrDomain string) (io.ReadCloser, error) {
	return c.queryFeed(query, manifestAddressOrDomain, false)
}
201196
func (c *syncClient) Get(arg0 string) (result []byte, err Error) {
	arg0bytes := []byte(arg0)

	var resp Response
	resp, err = c.conn.ServiceRequest(&GET, [][]byte{arg0bytes})
	if err == nil {
		result = resp.GetBulkData()
	}
	return result, err

}
1174844
func (s *GRPCStorage) Get(ctx context.Context, fn *FileNameMsg) (*ByteMsg, error) {
	data, err := s.backend.Get(fn.FileName)
	if err != nil {
		return &ByteMsg{}, err
	}
	return &ByteMsg{Data: data}, nil
}